|
Author |
Topic: deconstructors, object deletion, and memory (Read 325 times) |
|
mflux
|
deconstructors, object deletion, and memory
« on: Nov 24th, 2003, 1:17pm » |
|
I was wondering if it's beneficial, or even nessecary, to delete objects you have created once you're not using them. For example in C++ if you did leaf myLeaf=new leaf(); over and over again inside loop, it would become a memory leak. Is this the same in P5? So far evidence shows that this is not the case, but I want a real answer. I've been running into the java.lang.OutOfMemoryError error and I'm unable to run my program in P5 now. I was wondering if this was the cause.
|
|
|
|
toxi
|
Re: deconstructors, object deletion, and memory
« Reply #1 on: Nov 24th, 2003, 1:51pm » |
|
java usually does its own garbage collection, which is running in a low priority thread. however, the garbage collector (GC) only frees up resources for unreferenced objects. as long as at least one variable is still referring to an object, it can't be deleted. so you might still run out of memory if that is the case or you simply create objects so often and quickly, that the GC can't keep up... if you manually want to de-reference an object, simply do that for all vars pointing to it: myLeaf=null; hth!
|
http://toxi.co.uk/
|
|
|
mflux
|
Re: deconstructors, object deletion, and memory
« Reply #2 on: Nov 26th, 2003, 10:26pm » |
|
thanks for clearing that up for me toxi. You are always of great help.
|
|
|
|
|