March 01, 2005
Is it possible to cause an object to be deleted immediately rather than at the next GC sweep?  I ask because I am writing a DirectX engine.  Some things reside not in system RAM, but in video RAM, which is, AFAIK not managed by the GC.  It is bad to leave stuff laying around in video RAM as it's rather limited.  I'd rather not leave it up to the GC as to when those resources are deleted.

Is there any way to force immediate deletion of an object without manually running the GC?


March 01, 2005
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:d00dch$14fb$1@digitaldaemon.com...
> Is it possible to cause an object to be deleted immediately rather than at the next GC sweep?  I ask because I am writing a DirectX engine.  Some things reside not in system RAM, but in video RAM, which is, AFAIK not managed by the GC.  It is bad to leave stuff laying around in video RAM as it's rather limited.  I'd rather not leave it up to the GC as to when those resources are deleted.
>
> Is there any way to force immediate deletion of an object without manually running the GC?

Calling delete should run the destructor, if that is what you mean. It might
not immediately put the memory on the GC free list, but I can't remember
exactly. You are right that the GC won't touch video RAM. It gets its memory
from system RAM. So if you want to use the GC to help manage VRAM you should
make a lightweight object that holds video RAM:
class VRAM {
   void* ptr; // however one points to vram
   this(size_t s) { ... allocate ptr to vram ... }
   ~this() { ... destroy ptr to vram... }
}
int main() {
  VRAM obj = new VRAM(1000*float.sizeof);
  ... do stuff with obj.ptr ...
  delete obj; // release vram. otherwise will eventually be GC'ed
  return 0;
}

Or you can poke around with class allocators and deallocators.


March 01, 2005
> Calling delete should run the destructor, if that is what you mean.

Ah!  That's all I need then, as I can easily free the reference to the stuff in the video RAM in the object's destructor.  Just did some tests and that seems to be the case.

Thanks :)


Top | Discussion index | About this forum | D home