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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:53:20+00:00 2026-05-29T20:53:20+00:00

I am working on a project which basically involves parsing and storing information about

  • 0

I am working on a project which basically involves parsing and storing information about a large set of directories and files and gives me a summary of the number of files that were newly added (More like a ‘File Sniffer’).

The result of my program is that when I run it on say some 30 GB of data, I see the memory (working set) being allocated grow up to 700,000 K (memory leak).

In, my code, I am using quite a lot of object creation and destruction. The most used object is quite heavy.

Any suggestions as what could be done to reduce the memory usage. Please let me know if anything is unclear.

The main part of the code is something like this:

void analyzeHelper(std::string path){
    directory *dir=new directory();
    if(!dir->DirectoryExists(path))
        return;
    dir->SetCurrentDirectory(path);
    summary=new Summary();                        // Heavy class
    for(size_t i=0;i<dir->GetDirectories("*.*").size();i++)
        summary->addChild(dir->GetDirectories("*.*")[i]);
    for(size_t i=0;i<dir->GetFiles().size();i++)
        summary->addFile(Path<std::string>::toLower(dir->GetFiles()[i]));
    summary->setLocation(path);
    delete dir;
    compare(); //  here I run a comparision of the same directory with its previous version
    createMetadata(); // create an xml file to store the current version
    int size=summary->childSize();
    std::vector<std::string> _children=summary->getChildren();
    delete summary;
    for(int i=0;i<size;i++)
    {
        FileSniffer *f=new FileSniffer(xmlroot);
        f->setRoot(dirRoot,path,remroot);
        f->analyzeHelper(_children[i]);
        delete f;
    }

}

A related question: How bad is it to keep copying vectors? (As I am doing with ‘_children’ in the code)

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

    There is a memory leak if a directory does not exist:

    directory *dir=new directory();
    if(!dir->DirectoryExists(path))
        return;
    

    dir must be deleted before returning (a smart pointer would simplify the management of dir) or just allocate dir on the stack:

    directory dir;
    if(!dir.DirectoryExists(path))
        return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam working on a project which involves writing a Mork File (Mork is a
I'm working on a project which is just about to start, and since I
I'm working on a project which stores single images and text files in one
I am working on a project which will be using large datasets (both 2D
I am working on a project which is basically a Java application with an
I'm currently working on a project which involves optical character recognition in Android and
We are about to start a project which involves using a Sql Server 2005
I'm working on personal project which is basically a code editor. Imagine standard File
I'm working on a small project which will basically do some Facebook stuff and
I'm working on a Ruby on Rails (3 beta) project which is basically a

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.