Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.help Subject: Re: Disposing of Objects? Date: Tue, 15 Nov 2011 12:57:05 -0800 (PST) Organization: http://groups.google.com Lines: 49 Message-ID: <14147119.1197.1321390625791.JavaMail.geo-discussion-forums@prew38> References: <752b3c45-6455-4f52-8cf8-d2ba7714b51f@p16g2000yqd.googlegroups.com> Reply-To: comp.lang.java.help@googlegroups.com NNTP-Posting-Host: 2620:0:1000:2404:224:d7ff:fe69:5838 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1321390626 28170 127.0.0.1 (15 Nov 2011 20:57:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 15 Nov 2011 20:57:06 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:2404:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:1349 Davej wrote: > Stefan Ram wrote: >> Davej writes: >>> If I have global objects >> >> =A0 Such objects do not exist. >> >>> is it desirable to dispose of them before reinstantiating >>> them? >> >> =A0 Objects cannot be disposed nor reinstantiated. >=20 > Creating is not "instantiating?" Yes, yes it is. > q =3D new Mortgage(amt, term, int); This is creation, a.k.a. "instantiation" that you show here. > If q is a global and I execute the above statement again? Aa stated, and you quoted, there is no such thing as a "global" in Java. Regardless of what 'q' is, what you show is not "reinstantiation" but a new= instantiation. The result of the statement is that 'q' points to a newly created (or insta= ntiated) 'Mortgage' object and no longer points to anything else, if it eve= r did. If 'q' used to point to a different 'Mortgage' instance, now that instance = has one less reference to it. If 'q' happened to have held the very last r= eference to that instance, the instance has become an unreferenced object a= nd is eligible for garbage collection (GC). Objects in Java are not disposed, they simply lose all references to them. This is a rephrase of an earlier answer: =ABThe next third of your question is whether it's necessary to dispose of = such objects. The answer is the same for objects pointed to by a class or = by an instance of a class ('static' or instance member pointers, er, um, I = mean "references").=20 =ABNo. Just make sure there are no pointers left that reference that parti= cular object.=BB --=20 Lew