❔ Destroy objects in CSharp, IDisposable
Hi,
I am trying to get an object destroyed but it doesn't seem to be working.
I implemented IDisposable interface and started by just adding the
Dispose()
method, without any "destruction" I tried as they show on the documentation (simplified as far as I understand).
I also did use the
and when I checked for the object it was there still
any help with this?6 Replies
btw I understand the garbage collector takes care of destroying instances but I would really want to control this one, and make sure its no longer there
Objects being disposed doesn't mean they're being collected
You can use
GC.Collect()
to force the garbage collector to run, but it's usually a bad idea
You could try asking in #advanced maybe. Generally speaking, though, just let the garbage collector do its jobok thanks I will try
You really can't deterministically free managed memory in c#. It's not really even worth trying. If you really need that you can allocate and free blocks of native memory, but of course then you generally have to work with primitive types.
that sounds really complicated x) i just wanted to see the destructor in action, but the way i am doing i dont reach it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.