From: Combe, C. <C....@na...> - 2002-06-02 17:21:58
|
hi, I'm working on a project which uses 3 different views of the same thing. One representation is 2D, its a class that extends the normal AWT Canvas, the other 2 are different OpenGL representations that extend GLAnimCanvas. I'm trying to make a button that will swap between the views. The following code extract is from the action_performed method for the button. (I've never been sure about how much code to send into mailing lists, i didn't want to send in the whole project as there's alot of it. The way the canvas object gets cast to different types might look a bit funny, i think it has to be this way because of the way the interface class i'm putting between between the model and the different views works.) The displayPanel object is an instance of swing.JPanel. switch (canvasType) { case 1: displayPanel.remove((Canvas2D) canvas); canvasType = 2; canvas = new Shaded3D (800, 600); displayPanel.add((Shaded3D) canvas); break; case 2: displayPanel.remove((Shaded3D) canvas); ((Shaded3D)canvas).stop(); ((Shaded3D)canvas).destroy(); canvas = null; canvasType = 3; canvas = new Coloured3D (800, 600); displayPanel.add((Coloured3D) canvas); break; case 3: displayPanel.remove((Coloured3D) canvas); ((Coloured3D) canvas).stop(); ((Coloured3D) canvas).destroy(); canvas = null; canvasType = 1; canvas = new Canvas2D (); displayPanel.add((Canvas2D) canvas); break; } The problem is that when one of the GL canvases is destroyed (case 2 & case 3) they do not release all of the resources they were using - the amount of memory available goes down and the program slows down a bit. any suggestions about what i'm doing wrong? regards, colin |