Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 350877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:35:28+00:00 2026-05-12T11:35:28+00:00

One of the memory leaks I’ve discovered in our application is the java.awt.Window.allWindows private

  • 0

One of the memory leaks I’ve discovered in our application is the java.awt.Window.allWindows private static field, which keeps track of every Window instantiated. We have dialog boxes that are created, used, and then forgotten, and the expectation was that these would go away and be garbage collected. This private field keeps them in scope, indefinitely, until the dispose() method is called on them. And by definition, we can’t do that when they’ve gone out of scope.

I don’t understand why this is designed this way. It seems contrary to the spirit of garbage collection to have to explicitly let the system know when I’m done with a Window object. Obviously I’m done with it, as it is out of scope.

I understand what the dispose() method is doing: getting rid of system peer objects. I do understand that this is outside of Java and that you need some way to do that and that Swing shouldn’t just lose track of those objects, or else it would have a memory leak. But what is accomplished by keeping a reference to my Window around forever, when I am never going to use it again?

Can someone explain why this is necessary?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:35:28+00:00Added an answer on May 12, 2026 at 11:35 am

    I hate to say it, but that’s just how a GUI works.

    Windows are non-blocking. Meaning that once you create one in code, your code continues to execute.

    This means that your Window probably goes out of scope immediately after creation, unless you explicitly stored a reference to it somewhere else. The Window is still on screen at this point.

    This also means you need some other way to get rid of it when you’re done with it. Enter the Window dispose() method, which can be called from within one of the Window’s listeners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've had problems with memory leaks in our application. I've managed to replicate one
One of the frequent causes of memory leaks in .Net are event handlers which
I am using jProfiler to find memory leaks in a Java swing application. I
I have a memory leak on one of the part of my node.js application.
One of the following pieces of code generates a memory leak, any idea which
I'm trying to find a memory leak in one of our applications, however it's
What is the maximum memory one application can use? Please find instrument screenshot with
Which one is faster? Which one uses less memory? Console.WriteLine(string1) Console.WriteLine(string2) Console.WriteLine(string3) Console.WriteLine(stringNth) or
One of my VB 6.0 application throws an error Out of memory when loading
is there a way to detect simple memory leaks like this one with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.