[D-runtime] GC to track external memory?

Michel Fortin michel.fortin at michelf.com
Fri May 27 12:03:06 PDT 2011


Le 2011-05-27 à 13:24, Sean Kelly a écrit :

> Why is this needed?

Tracking Objective-C objects in my extern(Objective-C) addition to the compiler. The compiler would add the necessary calls to a runtime function that'd to make these Objective-C objects tracked by the GC.

> And FWIW this should be possible today by creating a class that references this memory and calls free() or whatever in its dtor.

Indeed. But that's not really an option in this case. Even if the compiler generated those wrappers automatically, this detail can't realistically be hidden away from the user and having two addresses for one object with two kinds of pointers you should't mix would be quite complicated and confusing.

Other options would be:

1. ask the user to do manual memory management with retain/release/autorelease
2. make the compiler smart enough to do retain/release/autorelease by itself most of the time, with some overrides so you can avoid cycles and such.

But having the D GC tracking Objective-C objects would allow them to behave just like regular D objects pretty much everywhere, which is basically my goal for this project.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the D-runtime mailing list