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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:49:37+00:00 2026-05-11T17:49:37+00:00

It seems that using Critical Sections quite a bit in Vista/Windows Server 2008 leads

  • 0

It seems that using Critical Sections quite a bit in Vista/Windows Server 2008 leads to the OS not fully regaining the memory.
We found this problem with a Delphi application and it is clearly because of using the CS API. (see this SO question)

Has anyone else seen it with applications developed with other languages (C++, …)?

The sample code was just initialzing 10000000 CS, then deleting them. This works fine in XP/Win2003 but does not release all the peak memory in Vista/Win2008 until the application has ended.
The more you use CS, the more your application retains memory for nothing.

  • 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-11T17:49:37+00:00Added an answer on May 11, 2026 at 5:49 pm

    Microsoft have indeed changed the way InitializeCriticalSection works on Vista, Windows Server 2008, and probably also Windows 7.
    They added a “feature” to retain some memory used for Debug information when you allocate a bunch of CS. The more you allocate, the more memory is retained. It might be asymptotic and eventually flatten out (not fully bought to this one).
    To avoid this “feature”, you have to use the new API InitalizeCriticalSectionEx and pass the flag CRITICAL_SECTION_NO_DEBUG_INFO.
    The advantage of this is that it might be faster as, very often, only the spincount will be used without having to actually wait.
    The disadvantages are that your old applications can be incompatible, you need to change your code and it is now platform dependent (you have to check for the version to determine which one to use). And also you lose the ability to debug if you need.

    Test kit to freeze a Windows Server 2008:
    – build this C++ example as CSTest.exe

    #include "stdafx.h" 
    #include "windows.h" 
    #include <iostream> 
    
    using namespace std; 
    
    void TestCriticalSections() 
    { 
      const unsigned int CS_MAX = 5000000; 
      CRITICAL_SECTION* csArray = new CRITICAL_SECTION[CS_MAX];  
    
      for (unsigned int i = 0; i < CS_MAX; ++i)  
        InitializeCriticalSection(&csArray[i]);  
    
      for (unsigned int i = 0; i < CS_MAX; ++i)  
        EnterCriticalSection(&csArray[i]);  
    
      for (unsigned int i = 0; i < CS_MAX; ++i)  
        LeaveCriticalSection(&csArray[i]);  
    
      for (unsigned int i = 0; i < CS_MAX; ++i)  
        DeleteCriticalSection(&csArray[i]); 
    
      delete [] csArray; 
    } 
    
    int _tmain(int argc, _TCHAR* argv[]) 
    { 
      TestCriticalSections(); 
    
      cout << "just hanging around..."; 
      cin.get(); 
    
      return 0; 
    }
    

    -…Run this batch file (needs the sleep.exe from server SDK)

    @rem you may adapt the sleep delay depending on speed and # of CPUs 
    @rem sleep 2 on a duo-core 4GB. sleep 1 on a 4CPU 8GB. 
    
    @for /L %%i in (1,1,300) do @echo %%i & @start /min CSTest.exe & @sleep 1 
    @echo still alive? 
    @pause 
    @taskkill /im cstest.* /f
    

    -…and see a Win2008 server with 8GB and quad CPU core freezing before reaching the 300 instances launched.
    -…repeat on a Windows 2003 server and see it handle it like a charm.

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

Sidebar

Related Questions

When I'm online it seems that everyone has agreed that using the exclusive locking
Seems that requirements on safety do not seem to like systems that use AI
When we remote a method (that is using generics) the remoting sink cannot seem
It seems that a List object cannot be stored in a List variable in
It seems that it is impossible to capture the keyboard event normally used for
It seems that Silverlight/WPF are the long term future for user interface development with
It seems that most of the installers for Perl are centered around installing Perl
It seems that anyone can snoop on incoming/outgoing .NET web service SOAP messages just
It seems that C# 3 hit me without me even noticing, could you guys
It seems that when I use a tool (such as winmerge) to update my

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.