Mem Mgmt: With & Without the GC

Zane via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 21 09:14:53 PDT 2016


Hey all,

My knowledge of GCs is limited, but my faith in them (for most 
applications) has greatly increased with advances (like with 
Golang's recent updates). I am now trying to get a better sense 
for the direction D is going regarding memory management, both in 
relation to the GC and without it. Excuse my ignorance, but can 
someone clarify the following for me?

1) If using the GC, but for whatever reason, I need to free 
something _right now_, is core.GC.free() the proper way to do 
this?

2) Does calling object.destroy() mean that the object is marked 
for future collection? If not, how can I ensure it is properly 
marked.

3) How can I mark a non-object for future collection? For 
example, a dynamic array: int[] a = new int[10];. Do I just set 
any references to null?

4) What if I want to immediately deallocate a dynamically 
allocated non-object (such as the dynamic array) - Can I use 
core.GC.free?

5) Is there a way to do simple heap allocation with 'new' while 
ensuring the GC doesn't deallocate until I want it to?

6) If the GC is off, how is allocation/deallocation handled? Can 
I still use new for example (and how do I dealloc)?

Thank you for any help you can provide.


More information about the Digitalmars-d-learn mailing list