This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
If a method has a return type, either a primitive or an Object type or any other user-defined type, what happens to the return value if it is not used. For eg., if I have a hashtable MyHash, I would use the put() method to fill it up. The put() has a return type of Object. However, I don't need the return type so I ignore it. Does the returned Object occupy any memory space...or is it garbage collected if it is not referenced....what happens to this lost value??
I think you can be assured that it will be available for garbage collection as soon as the method exits (i.e. returns). Just think of the return value as an assignment to a variable, as such MyObject = getMyObject(); // this method returns a MyObject The return value now has a reference and is not available for gc. Therefore, if you do this getMyObject(); then the MyObject instantiated in the method is not referenced and, therefore, is available for gc. Sean