We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to: delete object, make an array of objects
Pages: 1 2 
How to: delete object, make an array of objects (Read 6290 times)
Re: How to: delete object, make an array of object
Reply #15 - Jun 8th, 2005, 1:00pm
 
Sorry, Cosmin has the right idea. Any reference to an object in Java is just that, a reference. So an array of objects is just an array of references to objects, not an actual reserved memory space. That's why you have to initialize the objects explicitly before use. An array of int[] or float[] takes up a fixed reserved space, but an array of String[] is just an array of pointers to objects.

When you set an object reference in an array to point to a new object, Java marks the old object (which is no longer being referenced) for garbage collection. Essentially it's the same as setting the reference to a null value, but it might take the garbage collector a little longer to notice that the object should be deleted.

For a more geeky run-down of references in Java and their implications (i.e. the pass-by-reference vs. pass-by-value confusion), see the following:
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html
http://www.yoda.arachsys.com/java/passing.html

PS. It's technically possible to set up an array of java.lang.Object[], which then could be used to contain any kind of object since all classes are derived from java.lang.Object. However, this is far from advisable, since you'd have to check what kind of object each position in the array referred to.
Re: How to: delete object, make an array of object
Reply #16 - Jun 30th, 2008, 8:33pm
 
It seems like this problem was figured out by those who understood the changes made, but no one actually posted a fully working example. I'm really struggling with this.
Pages: 1 2