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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:30:26+00:00 2026-05-31T10:30:26+00:00

whenever I call a GC.Collect() or GC.GetTotalAmountOfMemory(true) the whole program just hangs. Now, I

  • 0


whenever I call a GC.Collect() or GC.GetTotalAmountOfMemory(true) the whole program just hangs. Now, I know what you gonna say: Don’t call GC.Collect() the GC takes care of itself. The problem is: It doesn’t in my case, something hangs around in memory and the GC can’t get rid of it.

I’ve no idea what it could be (project is big/old). I hope someone knows how to obtain informations about what the GC tries to do (and obviously can’t do) so that I can search for the problem or if something like a memory profiler could be of any help here (I’ve ANTS currently installed) and what I should search for.

*edit
something I totally forgot: Sometimes when I call one of the two methods of GC, the memory usage increases by ~10 kilobytes / second

*edit2
I’ve to correct myself: GC.Collect() runs just fine. Only GC.GetTotalMemory(true) hangs. GC.GetTotalMemory(false) works just fine, too.

*edit3
and yup as some of you already said: It seems to be a finalizer somewhere. When I run WaitForPendingFinalizers() it just sits there, doing nothing aswell.

ok, now I’m completely confused: When I enter a GC.GetTotalMemor(true) or a GC.WaitForPendingFinalizers() into the immediate window of Visual Studio after I paused the debugger, the program hangs (that’s what I did the whole time…I feel stupid now). When I add it to my usual source code and compile it, it works just fine.

Sorry about the whole fuzz, seems the memoryleak has another cause.

  • 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-31T10:30:27+00:00Added an answer on May 31, 2026 at 10:30 am

    Do you override any finalizers? When a finalizer is not returning ( Maybe you are waiting at any point for another thread ) the application may hang. The GC.Collect() invokes the finalizer but its never returning since it waits for a finalizer to return. This may be also the cause for your memory leak because the GC cannot finish the garbage collection.

    Solution

    You should be able to debug it, when the GC is collecting and you press "pause" it should show you the stack trace where it hangs. If everything goes wrong you maybe need to check the disassembly where your application is hanging.

    GetTotalMemory(true)

    This method forces the garbage collection, so it’s the same like GC.Collect().

    Update

    Lets take a look at GetTotalMemory:

    public static long GetTotalMemory(bool forceFullCollection)
    {
        long totalMemory = GC.GetTotalMemory();
        if (!forceFullCollection)
        {
            return totalMemory;
        }
        int remainingSteps = 20;
        long lastMemory = totalMemory;
        float num4;
        do
        {
            GC.WaitForPendingFinalizers();
            GC.Collect();
            totalMemory = lastMemory;
            lastMemory = GC.GetTotalMemory();
            num4 = (float)(lastMemory - totalMemory) / (float)totalMemory;
        }
        while (remainingSteps-- > 0 && (-0.05 >= (double)num4 || (double)num4 >= 0.05));
        
        return lastMemory;
    }
    

    As you can see that GetTotalMemory is waiting for finalizers, so it has to be a finalizer which hangs up the application. GC.Collect() is called when the finalizers are finished and will never be called because it never passes the line before.

    At any point in your application ( unsafe code? another thread? ) there is something which allocates a lot of memory while the GC never has the chance to clean up existing memory.

    Disclaimer

    This is a pure guess, i don’t know if the GC handles such situations but i think it cannot break the execution of a finalizer because it may take a long time and the GC doesn’t know if he is just hanging or still finalizing.

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

Sidebar

Related Questions

Suppose i have one simple function in my program. Whenever i call that function
right now whenever i call this function the value in B3 cell of excel
I'm writing a JApplet right now, and whenever I call super.paint(), the applet flickers.
Whenever I call this method in the Android emulator: SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); The
Whenever I call trigger(reloadGrid) on a JqGrid, it clears the existing table, displays a
Whenever I call my logger in a method, e.g. _logger.Debug(Connecting to database...); I get
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I'm working on a Perl module and whenever I call the skip() method I
I'm using the facebook graph PHP sdk - whenever I call the $facebook->api method
I am using following function. Whenever i call it that time it will increase

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.