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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:01:32+00:00 2026-05-13T17:01:32+00:00

I have written a small server application. It stores a lot of data in

  • 0

I have written a small server application. It stores a lot of data in strings. When stresstesting it, RSS memory grows (spotted by $top).

I have ran the program through “Instrument” – Mac OS X memory leak applicaton and it find only some minor leaks – the memory leaked was a couple of hundred bytes and the program continuously grows. When searching deeper, it seems like two functions is responsible for a large majority of the memory footprint:

std::string serialize()
{

 //Build basic message

 std::string result="";
        //std::cout << "result: " << result << "\n";
        result+=m_topic+d;
 //std::cout << "result: " << result << "\n";
 result+=m_message+d;
 //std::cout << "result: " << result << "\n";
 char buf[12];
 std::cout << m_severity << "\n";
 snprintf(buf, sizeof(buf), "%d", m_severity);
 //std::cout << "Buffer:" <<  buf << "\n";
 std::string temp(buf);
 result+=temp+d;
 //std::cout << "result: " << temp << "\n";

 int messagelength=strlen(result.c_str());
 snprintf(buf, sizeof(buf), "%d", messagelength);
 //std::cout << "Buffer:" <<  buf << "\n";
 std::string temp2(buf);
 temp2+=d;
 temp2+=result;
 //std::cout << "result: " << temp2 << "\n";
 return temp2;
}

and

std::string message::prettyPrint()
{
 struct tm *Sys_T= NULL;
 time_t Tval = 0;   
 Tval = time(NULL);
 Sys_T = localtime(&Tval);
 std::string date;
 char buf[10];
 sprintf(buf,"%d:%d:%d (%d/%d 2010)",Sys_T->tm_hour, Sys_T->tm_min, Sys_T->tm_sec, Sys_T->tm_mday, Sys_T->tm_mon);
 date+=std::string(buf);

 char sevbuf[10];
 sprintf(sevbuf,"%d",m_severity);

 delete Sys_T;
 std::string printed= "---------------------Message--------------------- \n";
 printed+= +"\n "+ date + ":  [[" +  getTopic() + "]]\n\n" +
 + " Message:" + m_message + "\n"
 + " Severity " + std::string(sevbuf) +" \n";
 //+ " Serialized " + serialize() + "\n";
 return printed;
}

As you can see this is merely stack allocated objects.

At the same time, the “Instrument” memory observer reports that the number of “active” allocated memory does not grow.

I am not so familiar with programming or these terms – my question is:

  • Can my application leak memory that is not reported by memory leak searching application?
  • Is RSS not reporting the “active” memory set but also the historical ones?
  • 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-13T17:01:32+00:00Added an answer on May 13, 2026 at 5:01 pm

    Even though your objects are merely stack allocated, the class implementations may allocate memory in the heap. For example, std::string will do this.

    Allocating and deallocating memory in the heap can lead to fragmentation, which would explain the increased memory usage. See http://en.wikipedia.org/wiki/Malloc#Heap-based

    Edit: Looking closer at your code, there are other problems — as the others have pointed out.

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

Sidebar

Related Questions

I have written a small custom web server application in C running on Linux.
I have written a small client server socket application. It is a proof of
I have written a small java application for which I need to obtain performance
I have a small AJAX application, written in PHP that I did not secure
I have written an AIR Application that downloads videos and documents from a server.
I have written a small HTTP server and everything is working fine locally, but
I have a small linux vps. I have written a Java client application, which
I have written a small perl application for deployment on a few servers. It
I have written a small Asp.net application using Entity Framework. A Stored Procedure accepts
I have written a small program and server to upload large files over HTTP

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.