Forums > Java

Max crash when deleting mxj


G
April 2, 2007 | 11:07 am

hi

i wrote an mxj object which includes a gui class (extends JFrame).
in this mxj, i overrided the notifyDeleted() method in order to clean the memory when deleted.
here is the method :

public void notifyDeleted(){
try{
this.gui.dispose();
this.finalize();
}
catch(java.lang.Throwable e){
//nothing
}
}

i do this because when i delete the mxj object when gui is open, the gui stays open and active.
but max crashes on the "this.gui.dispose();" (not responding anymore), and the gui.setVisible(false) doesn’t really kills the gui instance.

does anyone tried writing guis for mxj objects, or see a solution to my problem?

thanks

G.


April 2, 2007 | 12:40 pm

Hi,

It sounds like you could be having a deadlock with the mxj thread
waiting on the AWT event thread.

Try invoking dispose, which isn’t thread safe, on the AWT event thread
instead by:

SwingUtilities.invokeLater(new Runnable(){
public void run()
{
gui.dispose();
}
});

Note also, that dispose() frees up the resources needed for displaying
bits of the frame, but if you want the garbage collector to get rid of
the whole instance you’ll need to set the reference, this.gui, to null.

About your use of finalize(): IMO, if whatever you’ve got in there is
just a normal clear-up routine, call it something else because
finalize() is special (in that it /might/ be invoked before garbage
collection).

Finally, catch(Throwable ) is bad as it catches *absolutely everything*,
including descendants of RuntimeException and Error, which are there to
let you know either you’ve made a boo-boo or something’s really wrong
(things like NullPointerException, IllegalArgumentException,
OutOfMemoryError). As such, you *want* to know about these if they and
sort them out, for a life free of stress. At the very least, you should
do print the bare details of the problem to the max window, rather than
swallow it silently.

Also, catch(Throwable) or catch(Exception) tell you nothing about what
may be throwing the exception or what sort of exception it is – it’s
best to be as specific as you can be.


Owen

guillaume wrote:
> hi
>
> i wrote an mxj object which includes a gui class (extends JFrame).
> in this mxj, i overrided the notifyDeleted() method in order to clean the memory when deleted.
> here is the method :
>
> public void notifyDeleted(){
> try{
> this.gui.dispose();
> this.finalize();
> }
> catch(java.lang.Throwable e){
> //nothing
> }
> }
>
> i do this because when i delete the mxj object when gui is open, the gui stays open and active.
> but max crashes on the "this.gui.dispose();" (not responding anymore), and the gui.setVisible(false) doesn’t really kills the gui instance.
>
> does anyone tried writing guis for mxj objects, or see a solution to my problem?
>
> thanks
>
> G.
>
>



G
April 2, 2007 | 12:53 pm

thanks,

i knew i was doing something wrong… i have to learn a bit about this part of Java.


Viewing 3 posts - 1 through 3 (of 3 total)