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

  • Home
  • SEARCH
  • 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 7524989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:12:44+00:00 2026-05-30T03:12:44+00:00

I have a problem with memory use in my java app and for the

  • 0

I have a problem with memory use in my java app and for the life of me I can’t understand why the garbage collector isn’t sorting it out. The code is as follows:

public void foo() {
    for(int i=0; i<50000; i++) {
        bar(i);
    }
}

private void bar(int i) {
    LargeObject o = new LargeObject();
    ...
    dao.save(o);
}

My problem is that instances of LargeObject are not getting garbage collected – to identify this I’ve profiled with jprofiler and looked at the heap. LargeObject instances are never referenced by class variables, in fact they’re not referenced anywhere outside of bar(). I’m clutching at straws I feel but could this be related to where the transactions start/end? I’ve tried changing bar() to public and annotating with Propogation.REQUIRES_NEW and also changing the annotation on foo() to Propogation.NEVER to no avail.

The code inside the dao looks like this:

public void save(LargeObject o) {
    hibernateTemplate.getSessionFactory().getCurrentSession().saveOrUpdate(o);
}

The garbage collection definitely runs as I see it’s activity in jprofiler. foo() takes about 30 mins, bar() takes 36ms, garbage collection spikes roughly every 60 secs.

To answer the question why I know for sure they’re not being garbage collected – nothing in the system references LargeObject yet I see instances of them on the heap increasing as foo() is executing.

  • 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-30T03:12:45+00:00Added an answer on May 30, 2026 at 3:12 am

    Apparently they are referenced by your JPA provider (or whatever is hiding behind the dao.save()). You do let the reference outside, hence your control over it is lost. Whether you do it in a private/public method does not matter.

    You might want to share more information about this “DAO”.

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

Sidebar

Related Questions

I have a problem with out of memory when I'm trying load a few
I have a big problem with my application and the memory. The application (java
am having problem in Saving some data in my Java code. I have like
I have a problem with a memory leak in a .NET CF application. Using
We have a memory overwrite problem. At some point, during the course of our
My problem is: I have a perl script which uses lot of memory (expected
This is a C# problem. I have a big object in memory at a
I have a problem playing a sound correctly in Java using the Clip interface.
Most high-level languages (Python, Ruby, even Java) use pass-by reference. Obviously, we don't have
I have the following problem. I have C code that acquires a PNG image

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.