Why are my JDialogs leaking?

I have a JFrame, and I open JDialog from it and another JDialog from this dialog - in which menas I see 3 windows (JFrame, JDialog1, Jdialog2).

When I close both dialogs and run the garbage collector several times (from the netbeans profiler), I see that JDialog2 (the one that opens from JDialog1) is the garbage collection, but JDialog1 (opened from JFrame) is still hanging in the pool of live objects.

I create new objects every time - so after a while I have an OutOfMemoryError doue leak.

Do I need to treat JDialogs in a special way so that they don't leak?

By the way, I do setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE) in both dialogs,

+3
source share
3 answers

, dispose. .

+1

( )?

.

+9

What is your default close operation? From java JDialog api:

The default value is HIDE_ON_CLOSE.

What this means is basically that setVisible(false)or almost the equivalent of the one that gets called when the user clicks the close button. The behavior you observe is consistent with this.

Try

jDialog1.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
+4
source

Source: https://habr.com/ru/post/1707942/


All Articles