This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Iterating over a large list & memory leak

Hey, without getting into massive details of this app (since it is huge) I am getting a memory leak some place... Let me try to explain:

- I have a List<Order> that I am iterating over in a simple foreach. (this list has currently 8 thousand of "Orders")
- - as the List<Order> has increased in size, this memory issues has become more of a problem
- in that foreach loop I call a static method in a Drawing class called GenerateImage()
- in that method it generates a bunch of unique images and stores them in a Dictionary<string, Aurigma.GraphicsMill.Bitmap>
- once all of the unique assets have been created inside that Dictionary, I then place them onto a newly created destination Aurigma.GraphicsMill.Bitmap at predefined positions
- the dictionary is used to not have to create the same image multiple times as I place them onto the destination Aurigma.GraphicsMill.Bitmap
- the destination Aurigma.GraphicsMill.Bitmap is then returned

I am forcing garbage collection to occur to highlight the memleak in this process in the below:





I have a sneaking suspicion it has to do with the Dictionary<string, Aurigma.GraphicsMill.Bitmap>... but I am not sure how to proceed...

Please advise... Like I said, the app is massive with a lot of image dependencies so it is super difficult to share code snippets in a meaningful way... I will try to explain as much as I can if needed...
Are you disposing of the bitmaps in the dictionary at the end/once they aren't needed?
Does the memory use continue to go up forever or does it even out as that isn't a lot of memory being used by the process in that screenshot.
Chris Jones;32409
Are you disposing of the bitmaps in the dictionary at the end/once they aren't needed?
Does the memory use continue to go up forever or does it even out as that isn't a lot of memory being used by the process in that screenshot.


That is the start of the process... It will eventually use all memory and crash.

Here is what i hope is a helpful snippet what I am doing regarding the Dictionary:

            foreach (KeyValuePair<string, Aurigma.GraphicsMill.Bitmap> kvp in assetCache)
            {
                // iterate over every element that matches the kvp.key and put that image onto the base
                foreach (XElement elem in sheet.Data.Descendants("elem").Where(e => e.Attribute("type").Value == kvp.Key))
                {
                    if (elem.Attribute("vertical") != null && elem.Attribute("vertical").Value.ToLower() == "true")
                    {
                        kvp.Value.Transforms.Rotate(-90);
                    }

                    baseImage.Draw(
                        kvp.Value,
                        Convert.ToInt32(elem.Attribute("x").Value) - bleed,
                        Convert.ToInt32(elem.Attribute("y").Value) - bleed,
                        CombineMode.Alpha
                    );

                    //reset
                    if (elem.Attribute("vertical") != null && elem.Attribute("vertical").Value.ToLower() == "true")
                    {
                        kvp.Value.Transforms.Rotate(90);
                    }

                }
                kvp.Value.Dispose();
            }

            // attempt to solve mem leak
            assetCache.Clear();
            assetCache = new Dictionary<string, Bitmap>();
I have refactored out the need for a Dictionary, and the memory leak is still happening... so it isn't the disposing of the Dictionary items... As far as i know I am wrapping everything in a "using" so I have no idea...
It is still unclear how the assetCache collection is built.

Could you post a code where you init the assetCache variable?

foreach (KeyValuePair<string, Aurigma.GraphicsMill.Bitmap> kvp in assetCache)


BTW, what image formats do you process?
I will write a proof of concept app that highlights this when I get a chance. I am processing uncompressed 300DPI CMYK TIF's.

I had to come up with a solution quickly which took priority over tracking down the leak.

I will have the sample app done hopefully tonight.
Fedor;32412
It is still unclear how the assetCache collection is built.

Could you post a code where you init the assetCache variable?

foreach (KeyValuePair<string, Aurigma.GraphicsMill.Bitmap> kvp in assetCache)


BTW, what image formats do you process?


I have created an app that demonstrates the issue... how can I send it to you?
nokturnal
I have created an app that demonstrates the issue... how can I send it to you?


Please submit a case and attach the application.