Rank: Member
Groups: Guest
Joined: 3/21/2016(UTC) Posts: 23
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:
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
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 6/9/2016(UTC) Posts: 34
Thanks: 22 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.
|
|
|
|
Rank: Member
Groups: Guest
Joined: 3/21/2016(UTC) Posts: 23
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
Originally Posted by: Chris Jones 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>();
|
|
|
|
Rank: Member
Groups: Guest
Joined: 3/21/2016(UTC) Posts: 23
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...
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 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
|
|
|
|
Rank: Member
Groups: Guest
Joined: 3/21/2016(UTC) Posts: 23
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.
|
|
|
|
Rank: Member
Groups: Guest
Joined: 3/21/2016(UTC) Posts: 23
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
Originally Posted by: Fedor 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?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 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
|
|
|
|
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.