Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1349

Re: Disposing of Objects?

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Disposing of Objects?
Date 2011-11-15 12:57 -0800
Organization http://groups.google.com
Message-ID <14147119.1197.1321390625791.JavaMail.geo-discussion-forums@prew38> (permalink)
References <752b3c45-6455-4f52-8cf8-d2ba7714b51f@p16g2000yqd.googlegroups.com> <objects-20111115160120@ram.dialup.fu-berlin.de> <df8032d2-67d7-4527-aff4-ca195171f3c1@s7g2000yqa.googlegroups.com>

Show all headers | View raw


Davej wrote:
> Stefan Ram wrote:
>> Davej writes:
>>> If I have global objects
>>
>>   Such objects do not exist.
>>
>>> is it desirable to dispose of them before reinstantiating
>>> them?
>>
>>   Objects cannot be disposed nor reinstantiated.
> 
> Creating is not "instantiating?"

Yes, yes it is.

> q = 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 instantiated) 'Mortgage' object and no longer points to anything else, if it ever 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 reference to that instance, the instance has become an unreferenced object and 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:
«The 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"). 

«No.  Just make sure there are no pointers left that reference that particular object.»

-- 
Lew

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 06:59 -0800
  Re: Disposing of Objects? markspace <-@.> - 2011-11-15 07:08 -0800
    Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 08:17 -0800
      Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 09:56 -0800
        Re: Disposing of Objects? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-15 10:10 -0800
          Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 12:15 -0800
            Re: Disposing of Objects? markspace <-@.> - 2011-11-15 12:51 -0800
        Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 13:00 -0800
        Re: Disposing of Objects? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 21:59 -0500
          Re: Disposing of Objects? markspace <-@.> - 2011-11-15 19:13 -0800
            Re: Disposing of Objects? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 22:32 -0500
  Re: Disposing of Objects? Davej <galt_57@hotmail.com> - 2011-11-15 08:08 -0800
    Re: Disposing of Objects? markspace <-@.> - 2011-11-15 08:32 -0800
    Re: Disposing of Objects? Lew <lewbloch@gmail.com> - 2011-11-15 12:57 -0800
  Re: Disposing of Objects? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-16 06:23 -0800

csiph-web