GUJ
Notícias, artigos e o maior fórum brasileiro sobre Java
home
fórum
notícias
tópicos recentes
empregos
artigos
Bem-vindo ao GUJ.
Crie seu login
, ou digite-o para logar no site.
Usuário:
Senha:
JInternalFrame não coleta memória.
Índice dos Fóruns
»
Java Avançado
Autor
Mensagem
09/04/2007 14:39:43
Assunto:
JInternalFrame não coleta memória.
giovanni_stiwes
JavaGuru
Membro desde: 20/04/2006 09:00:42
Mensagens: 236
Offline
Veja o código:
import javax.swing.ImageIcon; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; /** * * @author Giovanni */ public class Desktop extends javax.swing.JFrame { private static final long serialVersionUID = 1L; private JDesktopPane desktopPane; public Desktop() throws Exception { initComponents(); } private void initComponents() throws Exception { desktopPane = new JDesktopPane(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); getContentPane().add(desktopPane, java.awt.BorderLayout.CENTER); } public JDesktopPane getDesktopPane() { return desktopPane; } public JInternalFrame openModule(final Class frameClass, final String name, final ImageIcon icon) throws Exception { for (int i = 0; i < 50; i++) { final int cont = i; JInternalFrame frame = new JInternalFrame(){ int[] i = new int[1000000]; @Override protected void finalize() throws Throwable { System.err.println("finalize-"+cont); super.finalize(); } }; // JInternalFrame frame = (JInternalFrame) frameClass.newInstance(); frame.setSize(800,500); frame.setTitle(name); // frame.setFrameIcon(icon); // Dimension desktopSize = desktopPane.getSize(); // Dimension frameSize = frame.getSize(); // Point location = new Point( // (desktopSize.width - frameSize.width)/2, // (desktopSize.height - frameSize.height)/2 ); // location.x = Math.max(0, location.x); // location.y = Math.max(0, location.y); // frame.setLocation(location); //[b]linha 57:[/b] desktopPane.add(frame); frame.setVisible(true); Thread.sleep(10); // desktopPane.remove(frame); frame.doDefaultCloseAction(); frame = null; System.gc(); } // return frame; return null; } public static void main(String[] args) { try { final Desktop desktop = new Desktop(); desktop.setSize(800,600); desktop.setVisible(true); SwingUtilities.invokeLater(new Runnable(){ public void run() { try { desktop.openModule(null, "", null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
O código acima coleta normalmente a memoria, mas se descomentar a linha 57 (desktopPane.add(frame)
, a coleta para de funcionar, alguem sabe porque.
Java SE 6
Windows XP SP2
no Java SE 5 tambem dá o problema.
Índice dos Fóruns
»
Java Avançado
Ir para:
Selecione um Fórum
Notícias
Assuntos gerais (Off-topic)
MundoJ - Artigos, Notícias e Debates
Artigos e Tutoriais
Java Básico
Java Avançado
Ferramentas, Frameworks e Utilitários
Desenvolvimento Web
Interface Gráfica
Google Android e Java Micro Edition (ME)
Certificação Java
Persistência: Hibernate, JPA, JDBC e outros
Java Enterprise Edition (Java EE)
Frameworks e Bibliotecas brasileiros
RIA - Flex, JavaFX e outros
Arquitetura de Sistemas
Metodologias de Desenvolvimento e Testes de Software
JavaScript
Ruby & Ruby on Rails
Outras Linguagens
Powered by
JForum 2.1.8
©
JForum Team