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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:58:52+00:00 2026-05-13T11:58:52+00:00

I’m having problems with a slow memory leak in my mixed mode C++/CLR .NET

  • 0

I’m having problems with a slow memory leak in my mixed mode C++/CLR .NET application.

(It’s C++ native static libraries linked into a VS2008 C++/CLR Windows Forms app with the “/clr” compiler setting)

Typical behaviour: app starts using 30 MB (private memory). Then leaks memory slowish, say a MB every hour when running under simulated heavy load. This simulates the app being live for days or weeks.

I’ve tried using several tools to track down memory leaks including both the CRT debugging stuff that comes with the Visual Studio CRT libs. I’ve also used a commercial leak detection tool (“Memory Validator”).

Both report negligible memory leaks at shutdown (a few minor entries that amount to a few KB that I’m not worried about). Also, I can see when running that the tracked memory doesn’t seem to amount to that much (so I don’t believe it is just memory that is being held and only released at app exit). I get around 5 MB of listed memory (out of total > 30MB).

The tool (Memory Validator) is setup to track all memory usage (including malloc, new, Virtual memory allocation and a whole bunch of other types of memory allocation). Basically, every setting for which memory to track has been selected.

The .NET image reports that it is using around 1.5 MB of memory (from perfmon).

Here’s a final bit of information: we have a version of the app which runs as a native console application (purely native – not CLR at all). This is 95% the same as the mixed mode except without the UI stuff. This doesn’t seem to leak memory at all, and peaks at around 5MB private bytes.

So basically what I’m trying to get across here is that I don’t think any of the native code is leaking memory.

Another piece of the puzzle: I found this which refers to memory leaks in mixed mode applications when targeting 2.0 framework (which I am): http://support.microsoft.com/kb/961870

Unfortunately the details are infuriatingly sparse so I’m not sure if it’s relevant. I did try targeting 3.5 framework instead of 2.0 but still had the same problem (maybe I didn’t do this right).

Anyone have any suggestions?

A few things that might help me:

  • Are there any other kind of memory allocations that I’m not tracking?
  • How come the figures don’t add up? I get 5 MB of CRT memory usage, 1.5 MB of .NET memory so how come the whole app uses 30MB private bytes? Is that all tied up in the .NET framework? Why don’t I see these in the leak tool? Won’t the .NET framework appear as some kind of allocated memory?
  • Any other leak detection tools which work well with mixed mode apps?

Thanks for any help

John

  • 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-13T11:58:52+00:00Added an answer on May 13, 2026 at 11:58 am

    OK I finally found the problem.

    It was caused by an incorrect setting for /EH (Exception Handling).

    Basically, with mixed mode .NET apps, you need to make sure all statically linked libs are compiled with /EHa instead of the default /EHs.

    (The app itself must also be compiled with /EHa, but this is a given – the compiler will report error if you don’t use it . The problem is when you link in other static native libs.)

    The problem is that exceptions caught in the managed bit of the app, which were thrown within native libraries compiled with /EHs end up not handling the exception correctly. Destructors for C++ objects are not then called correctly.

    In my case, this only occurred in a rare place, hence why it took me ages to spot.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.