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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:09:32+00:00 2026-06-10T13:09:32+00:00

I have a collection of data (Model) where each element has its visual representation

  • 0

I have a collection of data (Model) where each element has its visual representation (View) in a form of a JPanel with labels. Here is the method which updates a GUI Page:

public void updateGUIPage(){
    guiPage.removeAll();
    for(MyElement element: myCollection) {
        guiPage.add(new VisualElementWhichExtendsJPanel(element);
        guiPage.add(Box.createVerticalStrut(10);
    }
}

updateGUIPage() is called each time when collection changes. As you see, already created visual elements are removed (as I know from books, they will be later destroyed by Garbage Collector) and new visual elements are created for each element in the collection.
I don’t find this way to be very effective, but it simplifies very much application in general (as there are many GUIPages, and many of them show the same element, so if added to second GUIPage it will be removed from the first, that’s the way Swing works)
So, the question is: would you allow such approach in your application, or it’s better to make additional calculations and avoid excessive creation of new objects (considering that average size of collection will rarely exceed 100 members)?

  • 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-06-10T13:09:34+00:00Added an answer on June 10, 2026 at 1:09 pm

    So, the question is: would you allow such approach in your application, or it’s better to make additional calculations and avoid excessive creation of new objects (considering that average size of collection will rarely exceed 100 members)?

    The answer to that depends on the relative cost of creating the new objects versus the cost of updating them. And the only way to know for sure what those costs are is the measure them. (And the related question is whether absolute performance “hit” it doing this the slower way is enough to make a real difference …)

    However, this sounds to me like a case of premature optimization. I think you would be better of implementing the application the simpler way, and then seeing how well it performs. If it is too slow, then profile it to determine where the actual performance bottlenecks are. If the profiling tells you that this method is a significant bottleneck, consider doing something about it … otherwise, leave it alone.

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

Sidebar

Related Questions

I have constructed a collection of data series items. Each data series has multiple
I have a collection where all form data is stored, each form with a
In my Rails 3.2.6 app, I have a model representing a collection of data
I have a small data collection app which has a single button to start
I have a data model as follows: A Customer has Products and Payment Methods.
I have a form changeed the properties of my object CUSTOMER. Each customer has
I have to code: window.TicketCollection = Backbone.Collection.extend({ model:Tickets, url:/index.php/tickets/viewJSON }); window.TicketsView = Backbone.View.extend({ tagName:'div',
I have a collection which returns a model for each date within a given
In a hierarchical data model i have Parent and Child. Parent has Fields[] and
I have a data model which has two entities in a relationship of one

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.