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

The Archive Base Latest Questions

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

Good afternoon all, What I’m trying to accomplish : I’d like to implement an

  • 0

Good afternoon all,

What I’m trying to accomplish: I’d like to implement an extension to a C++ unit test fixture to detect if the test allocates memory and doesn’t free it. My idea was to record allocation levels or free memory levels before and after the test. If they don’t match then you’re leaking memory.

What I’ve tried so far: I’ve written a routine to read /proc/self/stat to get the vm size and resident set size. Resident set size seems like what I need but it’s obviously not right. It changes between successive calls to the function with no memory allocation. I believe it’s returning the cached memory used not what’s allocated. It also changes in 4k increments so it’s too coarse to be of any real use.

I can get the stack size by allocating a local and saving it’s address. Are there any problems with doing this?

Is there a way to get real free or allocated memory on linux?

Thanks

  • 1 1 Answer
  • 1 View
  • 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-12T08:30:12+00:00Added an answer on May 12, 2026 at 8:30 am

    I’d have to agree with those suggesting Valgrind and similar, but if the run-time overhead is too great, one option may be to use mallinfo() call to retrieve statistics on currently allocated memory, and check whether uordblks is nonzero.

    Note that this will have to be run before global destructors are called – so if you have any allocations that are cleaned up there, this will register a false positive. It also won’t tell you where the allocation is made – but it’s a good first pass to figure out which test cases need work.

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

Sidebar

Related Questions

Good Afternoon all, I'm trying to run a comparison of the contents of 2
I've spent a good while this afternoon trying to implement the deserialization of JSON
Good afternoon all, I have a class which looks like this: public class Grapheme
Good afternoon all, I was wondering what's the reason that public class test<T> {
Good Afternoon all , I have downloaded data from a web service and im
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main
Good afternoon all, I have a Java applet that I wish to embed on
Right, Good afternoon all (well, it is afternoon here in the UK!) I am
Good afternoon, all. I'm not too hopeful for a yes here, but if anyone
Good afternoon, I've run into some issues trying to combine HTTP caching with Rack::Cache

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.