HighTechTalks DotNet Forums  

Graphics.FromImage & Process memory usage

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Graphics.FromImage & Process memory usage in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jaret Brower
 
Posts: n/a

Default Graphics.FromImage & Process memory usage - 02-14-2006 , 09:17 AM






I'm loading several images from a database into memory, and when I do this
the memory usage for the process goes up in task manager by the size of the
bmp. After loading the image, I run the following code:

Bitmap bitmap = (System.Drawing.Bitmap)databaseBitmap.Clone();
Graphics graphics = Graphics.FromImage(bitmap);

The result of this code drops the process memory usage and the system memory
usage. I'm trying to figure out why, the only thing I can come up with is
that the memory is being pushed to the video card... Any ideas what is going
on?

Reply With Quote
  #2  
Old   
Jaret Brower
 
Posts: n/a

Default RE: Graphics.FromImage & Process memory usage - 02-14-2006 , 10:12 AM








"Jaret Brower" wrote:

Quote:
I'm loading several images from a database into memory, and when I do this
the memory usage for the process goes up in task manager by the size of the
bmp. After loading the image, I run the following code:

Bitmap bitmap = (System.Drawing.Bitmap)databaseBitmap.Clone();
Graphics graphics = Graphics.FromImage(bitmap);

The result of this code drops the process memory usage and the system memory
usage. I'm trying to figure out why, the only thing I can come up with is
that the memory is being pushed to the video card... Any ideas what is going
on?
After a little more testing it seems that the issue is due to a combination
of the clone and the FromImage calls. If I comment out the clone call, and
just do:

Graphics graphics = Graphics.FromImage(databasetBitmap);

there is no memory drop, and if i just do the Clone w/o the FromImage call
there is also no memory drop.


Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default RE: Graphics.FromImage & Process memory usage - 02-14-2006 , 10:15 PM



Hi Jaret,

Welcome to the MSDN newsgroup.

As for the memory behavior when calling the .NET Bitmap and Graphics
class's method, they're depending on the internal implementation and are
not documented. So generally such behavior is not reliable and it not
definitely deterministic. I think the video card memory could be one
possible reason, and since both Bitmap.Clone and Graphics.FromImage call
will need to allocate memory block for new objects, the system may swap
some physical memory into system memory paging file, thus the private bytes
used may drop some.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Reply With Quote
  #4  
Old   
Jaret Brower
 
Posts: n/a

Default RE: Graphics.FromImage & Process memory usage - 02-15-2006 , 08:31 AM



"Steven Cheng[MSFT]" wrote:

Quote:
Hi Jaret,

Welcome to the MSDN newsgroup.

As for the memory behavior when calling the .NET Bitmap and Graphics
class's method, they're depending on the internal implementation and are
not documented. So generally such behavior is not reliable and it not
definitely deterministic. I think the video card memory could be one
possible reason, and since both Bitmap.Clone and Graphics.FromImage call
will need to allocate memory block for new objects, the system may swap
some physical memory into system memory paging file, thus the private bytes
used may drop some.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


So the system paged memory won't show up in the total commit charged in task
manager? Because I'm seeing a drop here as well. I'm trying to do some
compression/local storage things with my images, but I'm having difficulty
because I'm not sure how much memory is actually being used, because of this
drop in memory. I lose ~75% of the processes memory after running those 2
lines of code.


Reply With Quote
  #5  
Old   
AT
 
Posts: n/a

Default RE: Graphics.FromImage & Process memory usage - 02-15-2006 , 09:07 PM



Thanks for your reply Jaret,

The task manager only has two columns on process memory usage(Memory Usage
and Virtual Memory size).

"Memory Usage" represent all the physical memory used by the process, so
this will be affect by memory swapping between physical memory and memory
paging file.

"Virtual Memory Size" , this represent all the virtual memory used by this
application in user mode. Though this is not all the virtual memory used by
the application(process), it can be used to evaluate the memory usage
condition of the process. So I think you can do your calculation according
to this value's change.

In addition, if you want more memory related data, I suggest you lookup the
process related performance counters in the system performance
monitor(perfmon).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.