Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

#drawing

Options
Go to last post Go to first unread
nokturnal  
#1 Posted : Wednesday, August 2, 2017 5:43:53 AM(UTC)
nokturnal

Rank: Member

Groups: Member
Joined: 3/21/2016(UTC)
Posts: 22

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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:


UserPostedImage


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...

Edited by user Wednesday, August 2, 2017 7:21:39 AM(UTC)  | Reason: Not specified

Chris Jones  
#2 Posted : Wednesday, August 2, 2017 7:45:46 AM(UTC)
Chris Jones

Rank: Advanced Member

Groups: Member
Joined: 6/9/2016(UTC)
Posts: 30

Thanks: 20 times
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.
nokturnal  
#3 Posted : Wednesday, August 2, 2017 8:08:18 AM(UTC)
nokturnal

Rank: Member

Groups: Member
Joined: 3/21/2016(UTC)
Posts: 22

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Chris Jones Go to Quoted Post
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:
Code:

            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>();
nokturnal  
#4 Posted : Wednesday, August 2, 2017 9:45:18 AM(UTC)
nokturnal

Rank: Member

Groups: Member
Joined: 3/21/2016(UTC)
Posts: 22

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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...
Fedor  
#5 Posted : Wednesday, August 2, 2017 4:47:06 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
It is still unclear how the assetCache collection is built.

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

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


BTW, what image formats do you process?
Best regards,
Fedor Skvortsov
nokturnal  
#6 Posted : Thursday, August 3, 2017 4:17:26 AM(UTC)
nokturnal

Rank: Member

Groups: Member
Joined: 3/21/2016(UTC)
Posts: 22

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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.
nokturnal  
#7 Posted : Thursday, August 3, 2017 11:16:52 AM(UTC)
nokturnal

Rank: Member

Groups: Member
Joined: 3/21/2016(UTC)
Posts: 22

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Fedor Go to Quoted Post
It is still unclear how the assetCache collection is built.

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

Code:
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?
Fedor  
#8 Posted : Thursday, August 3, 2017 5:47:09 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
nokturnal wrote:
I have created an app that demonstrates the issue... how can I send it to you?


Please submit a case and attach the application.
Best regards,
Fedor Skvortsov
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.