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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:51:30+00:00 2026-05-30T16:51:30+00:00

I have an application that works heavily with many custom objects that are created

  • 0

I have an application that works heavily with many custom objects that are created inside methods and never needed outside of them. The whole structure is (in my opinion) very good object oriented and uses Services, Utilities and a DI-Model.

Now, as I ran my first “large” tests, I quickly encountered OutOfMemoryExceptions. Now, I don’t just want to increase the heap space and be done with it, as I can imagine that will not solve the problem but rather delay it until my application has grown more and encounter the same problem then.

I’m looking for some simple and easy to implement solutions, tips and snippets that help an application deal with garbage collection and heap spaces, especially when it comes to many loops that operate with object creation.

Something like “don’t create objects in loops, create them before the loop and overwrite it within” and the sorts.

  • 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-30T16:51:32+00:00Added an answer on May 30, 2026 at 4:51 pm

    I would start out by profiling your application and looking for memory hot spots by using the jvisualvm (part of the JDK). This will give you and indication of how large your objects are and what method calls are resulting in high memory use. It will also tell you how long your objects are haning around in memory which is generally a good starting point as you want to reduce scope to be as short as possible.

    The next step is to identify commonalities in your objects either by refining your design or by implementing a cache. If you’re loading data from a fixed store then you could use softreferences so as the JVM runs out of heap these objects will be GCed (if your making changes to these objects you will obviously need to persist them before removing the hard reference). Then if they are needed again your application will simply need to reload them from the backing store (DB, files or whatever).

    Make sure you know how GC works and understand your object references:

    • Strong/Direct
    • Soft
    • Weak
    • Phantom

    Here are a few good articles which explain references and GC:

    http://www.java-tips.org/java-se-tips/java.util/using-weakhashmap-for-listener-lists.html

    http://pawlan.com/monica/articles/refobjs/

    http://www.kdgregory.com/index.php?page=java.refobj

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

Sidebar

Related Questions

We have an application that works with MS Office and uses Microsoft.mshtml.dll. We use
I have an application that works pretty well in Ubuntu, Windows and the Xandros
I have an application that works great on my development workstation but fails when
I have an application that works some what similar to how iPhone's Contact application
I have a web application that works in our stage/test environment fine but once
I have an application that perfectly works on iPhone os 2.2.1 but when I
We have a C# application that works fine on windows XP and windows vista
I have an application that is works fine and the JFrame for it is
I have a C++ application that works and compile perfectly. I can execute and
I have a Rails application that works with mongodb. I want to deploy it

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.