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


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

Re: Remove JFrame from memory

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Remove JFrame from memory
Date 2012-06-28 10:23 -0700
Organization http://groups.google.com
Message-ID <ec8352d5-09ef-4a62-87d3-b72492d251c9@googlegroups.com> (permalink)
References <84ceeec7-1304-4012-9255-62169dc8dc58@googlegroups.com>

Show all headers | View raw


Jesper Johnsen wrote:
> How do I remove an object lets say a JFrame from memory? 

Stop referring to it, then run out of 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? 

Others have answered, but the short version (as you would know from reading 
the documentation vis-à-vis garbage collection) is that you haven't run out of 
heap yet.

> package jframetest; 
> 
> import javax.swing.JFrame; 
> 
> public class JFrameTest { 
> 
>     public static void main(String[] args) { 
>         try{ 
>         Thread.sleep(5000); 
>     }catch(Exception Ex){} 
>         JFrame frame = new JFrame("Test"); 

You need to do GUI actions on the Event Dispatch Thread (EDT), 
not the main thread.

>         frame.setVisible(true); 

Ditto.

>          try{ 
>         Thread.sleep(5000); 
>     }catch(Exception Ex){} 
>          frame.setVisible(false); 

Ditto.

>          frame.dispose(); 
>          frame = null;   
>     while(1==1){ 
> try{ 
>         Thread.sleep(100); 
>     }catch(Exception Ex){} 
>     } 
>     } 
> 
> }

-- 
Lew

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


Thread

Remove JFrame from memory Jesper Johnsen <jsjohnsen.dk@gmail.com> - 2012-06-28 06:48 -0700
  Re: Remove JFrame from memory Knute Johnson <nospam@knutejohnson.com> - 2012-06-28 08:04 -0700
    Re: Remove JFrame from memory "John B. Matthews" <nospam@nospam.invalid> - 2012-06-28 22:02 -0400
  Re: Remove JFrame from memory Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-28 11:26 -0400
    Re: Remove JFrame from memory Jesper Johnsen <jsjohnsen.dk@gmail.com> - 2012-06-29 00:58 -0700
      Re: Remove JFrame from memory Lew <lewbloch@gmail.com> - 2012-06-29 13:39 -0700
  Re: Remove JFrame from memory Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-06-28 11:57 -0400
    Re: Remove JFrame from memory Jesper Johnsen <jsjohnsen.dk@gmail.com> - 2012-06-29 01:00 -0700
      Re: Remove JFrame from memory Jesper Johnsen <jsjohnsen.dk@gmail.com> - 2012-06-29 01:03 -0700
        Re: Remove JFrame from memory Lew <lewbloch@gmail.com> - 2012-06-29 13:41 -0700
  Re: Remove JFrame from memory Lew <lewbloch@gmail.com> - 2012-06-28 10:23 -0700
  Re: Remove JFrame from memory Roedy Green <see_website@mindprod.com.invalid> - 2012-06-29 04:05 -0700
    Re: Remove JFrame from memory Lew <lewbloch@gmail.com> - 2012-06-29 13:40 -0700

csiph-web