> > > Hi all, > > I am working with the GC and I need a little help, maybe someone can > help me. > I have the following code: > > ////////////////////////////////////////////// > import java.rem.RemObject; > import MyObject; > > class Test { > public static void main(String[] args) { > MyObject obj = new MyObject(); > RemObject.met1(obj); > obj = null; > System.gc(); > } > } > > ///////////// libraries/javalib/java/rem/RemObject.java > public class RemObject { > public static void met1(Object obj) { > nmet1(obj); > } > static native void nmet1(Object obj); > } > > //////////// libraries/clib/native/Remote.c > void > java_rem_RemObject_nmet1(struct Hjava_lang_Object* obj) { > ... > auxPtr = obj; // This is a global variable. > } > ////////////////////////////////////////////// > > The GC reaches the memory pointed by auxPtr and marks it Black. > I suppose that this happens because I have a pointer to that piece of > memory in auxPtr, but I can't figure out how it is reached by the > Collector. > In other words, I need to know if this memory is being used by the "user > Java program" (in this case, it is not), Could the Collector tell me > this? > No. A conservative collector such as Kaffes may keep a certain amount of floating garbage around. In other words, the collector will never collect objects that are in use, but it may sometimes retain objects that are not in use. You cannot assume the collector will free object that aren't in use, even if you explicitly null out references to them like you do with "obj=null". Secondly, the collector will not find the object via "auxPtr", as you surmise. If you wanted that, you needed to add a global ref (see gc_add_ref and/or the JNI methods if they work) like Archie said. - Godmar