I\'m using the LWJGL libraries and unfortunately I need to free up texture/vbo buffers myself whenever a node in my scene graph needs to die, I can\'t even use finalize() method
Disclaimer: I have not ever used PhantomReference.
However, I did read this article and this javadoc page, and so
Edit: Read the title of your post again. To answer the title question by itself: No, because a PhantomReference enters the ReferenceQueue after it has been gc'ed - so by definition it cannot be stopped from being gc'ed. To quote the first link: "The only use for such a reference [note: he means PhantomReference] is keeping track of when it gets enqueued into a ReferenceQueue, as at that point you know the object to which it pointed is dead"
Edit #2: I also think your code is wrong in that you should be initialising the phantom reference as follows (see a simple example here):
PhantomReference scenePhantomRef = new PhantomReference(scene, phantomQueue);
where scene
is the ScenePhantomReference
from your code (i.e. you should refactor your code so that ScenePhantomReference
is name e.g. Scene
, you instantiate it as scene
and then use the line above to get a handle on a PhantomReference
for that object).