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

The Archive Base Latest Questions

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

I am running memcheck on my program and i’m trying to solve the memory

  • 0

I am running memcheck on my program and i’m trying to solve the memory issues.

Memcheck output :

==29633== 3,443 (128 direct, 3,315 indirect) bytes in 2 blocks are definitely lost in loss record 7 of 8
==29633==    at 0x4A07D2E: operator new(unsigned long) (vg_replace_malloc.c:261)
==29633==    by 0x42027F: PDcbk(cpfrCallbackType_e, Powerdomain*) (NetExtractor.cpp:1243)
==29633==    by 0x413DBA: cpfparse() (cpf.y:120)
==29633==    by 0x42039B: loadCPF(char*) (NetExtractor.cpp:1253)
==29633==    by 0x420E5D: main (NetExtractor.cpp:1399)
==29633== LEAK SUMMARY:
==29633==    definitely lost: 128 bytes in 2 blocks
==29633==    indirectly lost: 3,315 bytes in 10 blocks
==29633==      possibly lost: 0 bytes in 0 blocks
==29633==    still reachable: 16,458 bytes in 3 blocks
==29633==         suppressed: 0 bytes in 0 blocks

Line 1253 of NetExtractor is :

powerdomainMap.insert(Powerdomain_pair(powerdomain->getName(),new Powerdomain(*powerdomain)));

Info to understand the code :

PowerdomainHashMap powerdomainMap;

typedef hash_map<const string, Powerdomain*, strptrhash, strptrequal> PowerdomainHashMap;
typedef pair<const string, Powerdomain*> Powerdomain_pair;

For now my guess is that there isn’t really a leak because i still can access the newly created powerdomain from my hashmap and that valgrind isn’t able to see that.

Am I right ? If not can someone explain me ?

Thanks and feel free to ask code details as i only pasted what i thought was relevant but i might have missed something.

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

    Well, you have map of pointers to dynamically allocated objects of class Powerdomain.
    The hash map itself did not allocate that memory, so it doesn’t clean it up for you.
    What you have to do is to free that memory yourself once you don’t need it, for example:

    for (PowerdomainHashMap::iterator i = powerdomainMap.begin (),
         e = powerdomainMap.end (); i != e; ++i)
    {
        delete i->second;
    }
    powerdomainMap.clear ();
    

    You probably never did that and Valgrind told you about that memory still being reachable upon the program termination.

    Now, if you really need that data during the life time of your application, then it is OK because OS will clean that memory when program exits anyway. But of course it is much better to do a clean shutdown, so that when this problems becomes a real problem you don’t ignore it by mistreating as OK behaviour.

    Aside from that, it seems like you are doing object copies anyway so I think it might be worth it to consider not working with dynamic memory explicitly and let hash_map worry about it. The data type declaration will look like this:

    typedef hash_map<const string, Powerdomain, strptrhash, strptrequal> PowerdomainHashMap;
    typedef pair<const string, Powerdomain> Powerdomain_pair;
    

    Hope it helps.

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

Sidebar

Related Questions

Running Ubuntu 11.04 on vagrant, mac os x 10.7.2. Running chef server. Trying to
I typed in >>valgrind ./myprogramname --tools-memcheck --leak-check=yes But the summary of the memory leaks
When running Valgrind's memcheck tool, I often get many hundreds of thousands (or more,
I am running memcheck using valgrind. the o/p is ==3091== 204 bytes in 17
Running sql server 2005 I have database A. I am trying to restore from
I have run my code through valgrind with these results: ==4492== Memcheck, a memory
I've tried running valgrind (memcheck and massif) on an app I wrote, but all
running: ruby 1.9.3p0 with Rails 3.2.1 Trying to use rspec but when I try
Running a rails site right now using SQLite3. About once every 500 requests or
running git instaweb in my repository opens a page that says 403 Forbidden -

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.