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 7180327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:19:26+00:00 2026-05-28T17:19:26+00:00

I have a container which switches its main content between several screen-sized panes. I’m

  • 0

I have a container which switches its main content between several screen-sized panes. I’m not using CardLayout, instead I’m using remove(previous); add(current); validate();

In this container I have data fields for each of these panes, which are initialized at startup so that I can easily just switch the reference between them.

My question:

If you remove the previous pane and add the new / current one, does the memory taken up by the previous pane’s instance object remain in memory?

Because I considered setting the previous pane to null and re-creating the current pane before adding it to the container in an attempt to lower memory usage, but wasn’t sure if it would actually make any difference.

Thanks. 🙂

EDIT: This isn’t actually my class but it demonstrates how I’m going about switching views:

public class ViewManager {

   public static final int VIEW_LOGIN = 0;
   public static final int VIEW_CALENDAR = 1;
   public static final int VIEW_HELP = 2;
   public static final int VIEW_SETTINGS = 3;
   public static final int VIEW_PREFERENCES = 4;
   public static final int VIEW_STATS = 5;

   private static LoginPane login = new LoginPane();
   private static CalendarView calendar = new CalendarView();
   private static HelpPane help = new HelpPane();
   private static SettingsPane accountSettings = new SettingsPane();
   private static PreferencesPane preferences = new PreferencesPane();
   private static StatsPane stats = new StatsPane();

   private static int previousView;

   private static Object [] views = {login, calendar, help, accountSettings, preferences, stats};

   // Without settings old views to null and re-creating incoming view request
   public static void switchTo(int currentView){
      if(currentView == previousView) return;

      MainFrame.getContent().remove(views[previousView]);
      MainFrame.getContent().add(views[currentView]);        
      MainFrame.getContent().validate();
   }

    // Settings to null and re-creating incoming view request
   public static void switchToNullify(int currentView){
      if(currentView == previousView) return;

      MainFrame.getContent().remove(views[previousView]);
      views[previousView] = null;

      if(currentView == VIEW_LOGIN)            views[VIEW_LOGIN] = new LoginPane();
      else if(currentView == VIEW_CALENDAR)    views[VIEW_CALENDAR] = new CalendarView();
      else if(currentView == VIEW_HELP)        views[VIEW_HELP] = new HelpPane();
      else if(currentView == VIEW_SETTINGS)    views[VIEW_ACCOUNT_SETTINGS] = new SettingsPane();
      else if(currentView == VIEW_PREFERENCES) views[VIEW_PREFERENCES] = new PreferencesPane();
      else if(currentView == VIEW_STATS)       views[VIEW_STATS] = new StatsPane();

      MainFrame.getContent().add(views[currentView]);
      MainFrame.getContent().validate();
   }
}
  • 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-28T17:19:27+00:00Added an answer on May 28, 2026 at 5:19 pm

    If you remove the previous pane and add the new / current one, does
    the memory taken up by the previous pane’s instance object remain in
    memory?

    Yes, unless you remove all references to that object. Once you’ve done that, it’ll be eligible for garbage collection.

    Because I considered setting the previous pane to null…

    Good idea!

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

Sidebar

Related Questions

I have a container element which I need to resize as its contents change.
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
I have a container class which uses boost::optional to hold the value. Here is
i have a container div which is position:relative and the squares are position:absolute because
I have a container of custom controls each of which have 2 controls in
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a function which searches an STL container then returns the iterator when
I have one std::list<> container and these threads: One writer thread which adds elements
I have a small floating UIView, viewHover, which acts as a container to 2
I am using an API (Let's pretend its facebook) to gather data between two

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.