Re: GC problem with large object - .net 1.1
- From: Barry Kelly <barry.j.kelly@xxxxxxxxx>
- Date: Thu, 21 Sep 2006 11:06:43 +0100
Rolf Welskes wrote:
I have an applications witch works with bitmaps.
Such bitmaps are in windows (forms) sizeable. Each time it is neccary to
allocate new bitmap with any size-step, because the bitmap
is generated.
You could consider using a larger bitmap than required and only using a
portion of it. That would avoid constantly resizing it for any size
step.
So there is the following situation under .net 1.1
If the window (bitmap) is sized for exampel 10 bitmaps are generated and
disposed in 2 seconds.
Because the GC does not make garbage collection directly, this costs 10 MB
ram instead of 1.
Are you really disposing the objects? That is, are you calling .Dispose
on the IDisposable Image, or using 'using' to limit the scope of the
images, etc.? When processing images etc., I *never* rely on the GC to
dispose of objects due to the working set peaks that causes.
Now some time later, maybe the GC makes a garbace collection.
Now GC-Memory has 10 MB used and 40 MB free.
BUT the GC does not give the memory back to the system.
(sometimes GC gives a little back to the system, but not all).
Means: for a long time you see 50 MB RAM resources used in the tasks manger,
what is not the reality, it's only 10 MB.
As you probably know, this is largely irrelevant. The numbers you can
find under Task Manager are either going to be "VM Size" (Private Bytes,
actual non-shared pages ultimately allocated using VirtualAlloc) or "Mem
Usage" (Working Set, the amount of memory that Windows has allocated to
the process for the moment, because that's how much it needs, under the
balance of current conditions and competing uses for the same memory, to
run without swapping). Many non-managed applications don't decrease
their private bytes unless they've implemented a custom memory manager.
Working set isn't going to decrease unless some event occurs which
causes the OS to recalculate the working set.
You've got to accept that "Free Memory" under Task Manager is actually
wasted memory. The ideal situation is for all memory to be allocated, if
not by processes, then by the system cache.
This problem is very hard, because customers see this in the task manager
und do not buy the product.
By that logic, people shouldn't run Firefox either, since it regularly
wanders up into 200 MB+ working set on my machine!
So question:
Is there any way under dot net 1.1 (.net net 2.0 is absolute impossible in
the moment because of many reasons),
to reduce the shown used Memory, which is wrong in the taskmanager for this
app.
Means is it possible to solve the problem when the bitmap is sized that
memory is not accumulated, because
with each new bitmap the old is disposed.
I think there will be no solution under .Net / C#, but would be fine.
But also a solution using C++ / unmanged code would be nice. (for the
allocation of memory of the bitmaps only).
You could investigate calling SetProcessWorkingSetSize() with a value of
-1. As the documentation says, this will cause the app to swap out to
disk.
-- Barry
--
http://barrkel.blogspot.com/
.
- References:
- GC problem with large object - .net 1.1
- From: Rolf Welskes
- GC problem with large object - .net 1.1
- Prev by Date: Re: Adding contraints and inheriting
- Next by Date: Re: Hang when new DirectoryEntry declared
- Previous by thread: GC problem with large object - .net 1.1
- Next by thread: RE: GC problem with large object - .net 1.1
- Index(es):
Relevant Pages
|