Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!204.52.135.9.MISMATCH!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Closing/Despose of JFrame Date: Thu, 28 Jun 2012 07:22:02 -0700 Organization: A noiseless patient Spider Lines: 26 Message-ID: References: <5752befc-aca1-46f9-81d9-f3992bf756e7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 28 Jun 2012 14:22:04 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Aj4gkJnboYPtscrbpd0V8g"; logging-data="4071"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197naNX90PgxCTHn2nMB6B08B63UoQE7L8=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <5752befc-aca1-46f9-81d9-f3992bf756e7@googlegroups.com> Cancel-Lock: sha1:UxWRAy1mEb6b2jzOmphjd7tCkkE= Xref: csiph.com comp.lang.java.programmer:15717 On 6/28/2012 6:38 AM, Jesper Johnsen wrote: > How do I remove an object lets say a JFrame from memory? > I know that the garbage collector handles this - but this simple example does not release itself... > java.exe uses 10mb in the first wait stage, this increases to 20mb when the JFrame is shown, but the memory usage never returns to the initial 10mb. > So the garbage collector never removes the object from memory - why? Why? Because the garbage collector never needs to remove the object. You're using 20mb out of maybe 100mb to 1000mb or more? So the garbage collector looks at that and says "plenty o' room left!" and doesn't run. It's weird if you're used to having explicit control over object destruction, but it works. More importantly it's efficient. Waiting, and then removing lots of objects at once, is actually best for throughput in the long run. If you really need different behavior, check out Oracle's documentation on tuning the garbage collector. You can choose what I believe is called an incremental garbage collector which will work more like what you are thinking. Found via Google with search terms "java garbage collection tuning". Learn to STFW.