• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog not disposing child JDialog  RSS feed

 
Cy Bird
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one JDialog that creates a new local variable of type JDialog. I do a .show() on the child to show it and do a setVisible(false) on the parent to hide it.
Inside the child on an action performed I do a dispose(). But the finalize is not actually executed until the parent is finalized. This is a problem because I want to cache the first dialog and re-use if for the life of the app.
Ideas?
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your parent dialog (or any other objects) have a handle to this child that might be keeping it from GCing?
If you are worried about the memory space it takes, why are you keeping the parent dialog around either?
If you need something to happen that you set up in a custom finalize(), why not just move it to a different method you call instead of dispose() that will then do your special thing and then call dispose() itself.
Just some questions that might help clarify your needs...
HTH
 
Cy Bird
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only reason I was looking into reusing the parent was for performance reasons. However, it seems to be a domino effect... the parent isn't releasing the child, and the child isn't releasing the grandchildren. How can I troubleshoot what might be holding a reference? Any pointers?
Thanks.
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is your parent dialog a very complex/expensive one to create? Does it get called alot?
As to watching handles, you really just have to check your code and make sure all references to the child is released. As a dialog tho, I wouldn't expect handles to be spread around very much. dialogs usually are one off items that don't need to be *handled* except when called because they are recreated when you need them. Do you use a global variable to when you create the child? Can you show me a bit of code on how you call the child? It might help. If you use a global/object variable when you create the child instead of a local(only valid inside that method) one, then that would possibly explain whats happening. Show me some code and maybe I can help more.
 
Cy Bird
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- It is fairly expensive (4 JTables and a bunch of JCheckboxes). It is called very often.
- I found out what method is causing things to not release (when I comment out it's released after 2 gc). Now just need to figure out why. We're doing some static calls, so I think that might be a player.
Thanks for the help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!