
Signature
.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn Great reviews & good sales.
>> The problem comes in where I want to know when there are no more barrels
>> so that I can call Dispose on my vertex and index buffer! I can not
[quoted text clipped - 16 lines]
> Dispose to free memory; you only need to Dispose to do things like
> closing handles.
Hi Jon -
Thanks for the reply.
Sadly, my example is simplified. In reality, I'm trying to unload a
substantial amount of geometry so that I can load in lower
level-of-detail models, and loading in entirely new pieces of geometry.
This requires me to unload the unused geometry immediately, otherwise
the video card will just run out of memory. Since I can't tell if the
geometry data object is still needed, I can't unload it.
The GC doesn't seem to realize that it needs to unload some of this
stuff because the objects seem to have much smaller memory footprints
than they actually do, and even if the GC did know how big they are it
doesn't understand that there are seperate memory resource pools. Also
calling GC::Collect() doesn't seem to be cleaning them up either.
- John
Barry Kelly - 02 Sep 2006 15:52 GMT
> The GC doesn't seem to realize that it needs to unload some of this
> stuff because the objects seem to have much smaller memory footprints
> than they actually do
BTW, this is the reason for GC.AddMemoryPressure() and
GC.RemoveMemoryPressure() in .NET 2. You have to tell the GC in your
constructor / reallocate / finalize methods.
> and even if the GC did know how big they are it
> doesn't understand that there are seperate memory resource pools.
> Also
> calling GC::Collect() doesn't seem to be cleaning them up either.
I'm not sure exactly what this refers to: do you mean that your objects
are being kept alive from somewhere? Or does it mean that you haven't
implemented finalization on your objects properly?
FWIW, manual resource management hasn't gone away. When the resource
isn't managed memory, you've still got to do it yourself, using
IDisposable, 'using', C++/CLI & smart pointers & RAII, etc. To get good
performance in a number of scenarios I've found it necessary to reinvent
the memory allocator etc. YMMV.
-- Barry

Signature
http://barrkel.blogspot.com/
Jon Shemitz - 02 Sep 2006 17:10 GMT
> Sadly, my example is simplified. In reality, I'm trying to unload a
> substantial amount of geometry so that I can load in lower
> level-of-detail models, and loading in entirely new pieces of geometry.
> This requires me to unload the unused geometry immediately, otherwise
> the video card will just run out of memory. Since I can't tell if the
> geometry data object is still needed, I can't unload it.
In other words, you have to do some cleanup on the video card when you
are done with a geometry object?
If all the vertex and index buffers are actually unmanaged resources
on the video card, one alternative to reference counting is to rely on
finalizers. Normally, this is an expensive no-no, but if resurrection
costs are low (because the geometry objects contain no references to
other managed memory) finalization may be cheaper and more reliable
than reference counting, and the biggest issue may be the lag between
delinking a geometry object and actually freeing the associated video
memory.
> The GC doesn't seem to realize that it needs to unload some of this
> stuff because the objects seem to have much smaller memory footprints
> than they actually do, and even if the GC did know how big they are it
> doesn't understand that there are seperate memory resource pools. Also
> calling GC::Collect() doesn't seem to be cleaning them up either.
I'm not at all sure what you mean, here: the gc is very good at
tracing dependencies, and WILL reclaim a whole object graph when you
no longer refer to the root.

Signature
.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn Great reviews & good sales.