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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:47:09+00:00 2026-06-15T23:47:09+00:00

I have a very weird problem with GC in Java. I am running th

  • 0

I have a very weird problem with GC in Java. I am running th following piece of code:

 while(some condition){
        //do a lot of work...
        logger.info("Generating resulting time series...");
        Collection<MetricTimeSeries> allSeries = manager.getTimeSeries();
        logger.info(String.format("Generated %,d time series! Storing in files now...", allSeries.size()));

        //for (MetricTimeSeries series : allSeries) {
           // just empty loop
        //}
 }

When I look into JConsole, at the restart of every loop iteration, my old gen heap space, if I manually force GC, takes a size of about 90 MB. If I uncomment the loop, like this

 while(some condition){
        //do a lot of work...
        logger.info("Generating resulting time series...");
        Collection<MetricTimeSeries> allSeries = manager.getTimeSeries();
        logger.info(String.format("Generated %,d time series! Storing in files now...", allSeries.size()));

        for (MetricTimeSeries series : allSeries) {
           // just empty loop
        }
 }

Even if I force it to refresh, it won’t fall below 550MB. According to yourKit profiler, the TimeSeries objects are accessible via main thread’s local var (the collection), just after the GC at the restart of a new iteration… And the collection is huge (250K time series.)… Wyy is this happening and how can I “fight” this (incorrect?) behaviour?

  • 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-15T23:47:10+00:00Added an answer on June 15, 2026 at 11:47 pm

    Since you’re building a (large) ArrayList of time series, it will occupy the heap as long as it’s referenced, and will get promoted to old if it stays long enough (or if the young generation is too small to actually hold it). I’m not sure how you’re associating the information you’re seeing in JConsole or Yourkit to a specific point in the program, but until the empty loop is optimized by several JIT passes, your while loop will take longer and keep the collection longer, which might explain the perceived difference while there’s actually not a lot.

    There’s nothing incorrect about that behaviour. If you don’t want to consume so much memory, you need to change your Collection so it’s not an eagerly-filled ArrayList, but a lazy collection, more of a stream (if you’ve ever done XML processing, think DOM vs SAX) which gets evaluated as it’s iterated. If you don’t need the whole collection to be sorted, that’s doable, especially since you seem to be saying that the collection is a concatenation of sub-collections returned by underlying objects.

    If you can change your return type from Collection to Iterable, you could for example use Guava‘s FluentIterable.transformAndConcat() to transform the collection of underlying objects to a lazily-evaluated Iterable concatenation of their time series. Of course, the size of the collection is not directly available anymore (and if you try to get it independently of the iteration, you’ll evaluate the lazy collection twice).

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

Sidebar

Related Questions

I have a very weird problem in the most simple piece of VB.NET code:
So I have a very weird problem. I am writing some code in VB.Net
I have a very weird problem that I can't understand. This is C code:
I have a very weird problem using OpenMP in my C++ code: void update(double
Today, i have very weird problem with trim function. Here is my code. =and
I have very weird problem with web-services. Setup is following: 6 web-services deployed on
I have a very weird problem. I am using PHP, in my PHP code,
I have a very weird problem. I have a webpage that displays some graphs
I have the following, very weird problem with my WPF app in production environment:
I have a very weird problem while trying to pass and SQL query using

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.