[859] in java-interest

home help back first fref pref prev next nref lref last post

Idem: memory deallocation

daemon@ATHENA.MIT.EDU (JD Brennan)
Fri Aug 11 20:00:07 1995

Date: Fri, 11 Aug 1995 09:59:10 -0700
From: JD Brennan <brennan@symbologic.com>
To: Francois Boussard <francois@coplanet.fr>
Cc: java-interest@java.sun.com
In-Reply-To: <17787890@toto.iv>
Reply-To: JD Brennan <brennan@symbologic.com>

There are no value semantics in Java.  Everything is reference
semantics.  So there are no objects allocated on the stack, so 
no local objects.  Althought tmp looks like a C/C++ stack-allocated
local variable, in Java it's a reference to a heap allocated object.
So you have a local reference to a heap allocated object, which can
easily be assigned to a global reference which now points the same
heap allocated object.  The scope of the object hasn't changed.  Just
the scope of the reference to it.

JD Brennan
[brennan@symbologic.com               Symbologic Corp., Seattle, WA]

Francois Boussard writes:
 > > Jonathan Fine (jfine@umich.edu)
 > > Tue, 8 Aug 1995 16:05:20 -0400 (EDT)
 > > 
 > > I was wondering how java does memory deallocation since, as far as I
 > > know, there is no free() or delete library functions. In the example
 > > below, what happens to the memory originally allocated to list?
 > > 
 > > Is that memory automagically deallocated, or are there destructors or
 > > library functions I am unaware of?
 > > 
 > > Thanks.
 > > 
 > > import browser.Applet;
 > > 
 > > class Test extends Applet {
 > > String list[] = { "lions", "tigers", "bears" };
 > > 
 > > public void init() {
 > > String tmp[] = new String[list.length+1];
 > > System.arraycopy( list, 0, tmp, 0, list.length );
 > > list = tmp;
 > > list[3] = "foobar";
 > > 
 > 
 > 	I am also interested by this point ! :
 > 	I HOPE that when no pointers points to a memory object, the garbage
 > free it. 
 > 	So, what i've understood is :
 > 	- your first list {"lions"...} is freed cause theres is no more 
 > 	reference pointing to it.
 > 
 > 	- the second list (from tmp) will still stay alive after end of init()
 > 
 > 	- so, a local object (tmp) can in fact become global if a global
 > 	reference points to it.
 > 
 > 	Well, now I am not an expert in Java, but that what i've understood.
 > 	Perhaps someone from java-team could confirm it ?
 > 
 > 	Thanks, bye.
 > - -- 
 > __________________________________________________________________________
 > Francois BOUSSARD        
 > CoPlaNet : 3 Rue J.Guesde . 92309 . Levallois
 > francois@coplanet.fr
 > __________________________________________________________________________
 > 
 > 
 > 
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post