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!novia!news-out.readnews.com!news-xxxfer.readnews.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 08:17:22 -0800 (PST) Organization: http://groups.google.com Lines: 30 Message-ID: <14847360.425.1321373842152.JavaMail.geo-discussion-forums@prgt40> References: <752b3c45-6455-4f52-8cf8-d2ba7714b51f@p16g2000yqd.googlegroups.com> Reply-To: comp.lang.java.help@googlegroups.com NNTP-Posting-Host: 67.218.103.201 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1321373854 18016 127.0.0.1 (15 Nov 2011 16:17:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 15 Nov 2011 16:17:34 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=67.218.103.201; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:1339 markspace wrote: > Davej wrote: >> If I have global objects is it desirable to dispose of them before >> reinstantiating them? Thanks. > > I'm with Stefan in that I don't think your questions makes a lot of > sense. In some cases, it makes sense to create a new object rather than > reuse an old one, but in some cases it doesn't. It depends; mostly on a > lot of things that you haven't shared with us. Here's an outline of an introduction to a primer on Java's memory allocation model. Nothing is global, in the sense that there is at least one 'Object' in every Java program, the main class class instance. Yes, I said, "class class". For every class ('Foo') there is one class object called 'class' ('Foo.class') that represents the entire class. The class object for your main class kicks off the whole Java program. Everything else in the program is either a primitive like 'int' or 'boolean', another class's class instance, or an instance of some class, perhaps the main class itself or 'String' or what-have-you. That's why there are no true global objects in Java. Everything belongs to some class or other, or to an instance of some class or other. But, wait! Belonging to a class is pretty close to global. If a class member is 'static', it is accessible at the class level (and only there) without need for an instance. 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. What do you mean by "reinstantiating"? -- Lew