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

  • Home
  • SEARCH
  • 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 441605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:59:21+00:00 2026-05-12T20:59:21+00:00

I’m running valgrind 3.5.0 to try and squash memory leaks in my program. I

  • 0

I’m running valgrind 3.5.0 to try and squash memory leaks in my program.
I invoke it as so:

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes

After my program finishes valgrind reports that

==22926==
==22926== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)
==22926== malloc/free: in use at exit: 20,862 bytes in 425 blocks.
==22926== malloc/free: 25,361 allocs, 24,936 frees, 772,998 bytes allocated.
==22926== For counts of detected errors, rerun with: -v
==22926== searching for pointers to 425 not-freed blocks.
==22926== checked 91,884 bytes.

Despite telling me that there are 0 errors I’m concerned that the number of allocations and frees do not match. More
worrisome still is the following:

==22926== LEAK SUMMARY:
==22926==    definitely lost: 68 bytes in 1 blocks.
==22926==    indirectly lost: 20,794 bytes in 424 blocks.
==22926==      possibly lost: 0 bytes in 0 blocks.
==22926==    still reachable: 0 bytes in 0 blocks.
==22926==         suppressed: 0 bytes in 0 blocks.

There is additional output, pertaining to what appears to be a leak:

==22926== 20,862 (68 direct, 20,794 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 17
==22926==    at 0x40269EE: operator new(unsigned int) (vg_replace_malloc.c:224)
==22926==    by 0x807960B: OneTwoThree::OneTwoThree(Scenario const*) (onetwothree.cc:22)
==22926==    by 0x804DD69: main (scsolver.cpp:654)

At the line in question in the constructor of OneTwoThree I have the following:

OneTwoThree::OneTwoThree (const Scenario* scenario) :
    Choice("123", scenario, new Solution (scenario->name(), scenario)),
    seen_(new bool [sol_->numVisits()])
{
}

later, in the destructor, seen_ is deleted as so:

OneTwoThree::~OneTwoThree ()
{
    delete [] seen_;
}

There is no reallocation of memory associated with seen_; I only flip the bools to true/false during the course of
running my program.

I can’t see a leak here and I don’t understand what valgrind is trying to tell me. I’ve been reading through the
valgrind manual (specifically, this) but
I’m not being enlightened much.

Can anyone help me grok this output?

  • 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-12T20:59:21+00:00Added an answer on May 12, 2026 at 8:59 pm

    The commenters to the OP were spot on; The Solution object being created in the constructor was never being deleted. I’ve fixed the egregious oversight and gotten rid of the ugly code creating new objects outside of the constructor of the object which is responsible for them.

    Thank you Artelius, Nikolai and Jonathan!

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.