Rank: Newbie
Groups: Guest
Joined: 7/16/2009(UTC) Posts: 7
|
I have a bitmap (dimensions 2688x3581x24bpp) which I load in via an IFrame. I do this because I want to show the metadata about the image in my UI without loading the 27MB of image to do it. IFrame allows me to do this. I do however need to load this image at times, and so as I already have a reference to the IFrame I call GetBitmap on the IFrame. Bitmap bitmap = new Bitmap(); frame.GetBitmap(bitmap); Now prior to the GetBitmap() call my memory usage (measured using performance counters Process/Private Bytes) my memory usage is 37MB. The Bitmap takes up 27MB (according to my calculations and the MemoerySize property). After GetBitmap my memory usage is around 120MB. Even after calling GC.Collect()/WaitForPendingFinalizers()/Collect(). I've written a test app which dumps the memory usage to screen - Start memory Usage 39.17578 Loaded to IFrame 60.85547 Created Empty Bitmap 62.375 Called GetBitmap() 117.832 Called GC.Collect()/WaitForPendingFinalizers()/Collect() 117.8438 The Call to GetBitmap makes memory jump 55MB - very close to 2*27MB! Any thoughts/ideas? I can share my code if required. Edited by user Wednesday, September 30, 2009 6:23:50 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 7/16/2009(UTC) Posts: 7
|
The source for the above issue can be downloaded here DownloadIts purely intended to show the issue, and I'm fully aware that I'm not freeing all my own resources, although at the point of writing the memory usage this isnt important. Edited by user Wednesday, September 30, 2009 5:56:47 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, Good question! Yeap, these 55Mb are 2 * 27Mb. The reason is that IFrame object stores its own copy of the decoded Bitmap inside. Here is output of your test application with a little modification: Code:Start memory Usage
24.65625
Loaded to IFrame
29.83203
Created Empty Bitmap
32.29688
Called GetBitmap()
87.67969
Called frame.Dispose()
60.24219
Called bitmap.Dispose()
32.76563
Such memory overhead is necessary to allow code like this: Code:FormatReader r = <somehow_create_reader()>;
IFrame frame = r.LoadFrame(0);
Bitmap bmp = new Bitmap();
frame.GetBitmap(bitmap);
<... do some modifications to bitmap ...>
//And after that:
FormatWriter w = <somehow_create_writer()>;
w.AddFrame(frame); //Store original image without any modifications.
//Or:
Bitmap another_bmp = new Bitmap();
frame.GetBitmap(bitmap); //Immediatly get another clean copy of frame image.
In your case you should extract all necessary info from IFrame object and dispose it as soon, as possible. |
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 7/16/2009(UTC) Posts: 7
|
OK, cheers.
It looks like I'll use IFrame for loading metadata, and manually load a Bitmap outside IFrame if I require one.
N
|
|
|
|
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.