Results 1 to 13 of 13

Thread: problem with memory alocation

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    9

    Question problem with memory alocation

    Hi to all!

    Some time ago I have a strange problem with memory alocation (while using stl containers). I attached c++ source files (ok.cpp and fail.cpp). In ok.cpp everything work "almost" fine, I mean almost all the memory is released after deleting all the elements. BUT the number of 500*8 elements on the list seems to be a limit somehow. In fail.cpp, the number of elements on the list is 500*16 (the size of single element is decreased to 1024*64 from 1024*128). Here, after deleting all the elements of the list and going out of the scope where the list is declared, there is no memory released.
    1 How is that possible?
    2 What to do? How to fix it?
    Thanks for ANY help.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: problem with memory alocation

    I dont see any attached files.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    31

    Re: problem with memory alocation

    1. "no memory released" it means that the process does not release some memory to the OS?
    2. If so, it is possible because the standard memory allocator builds its own structures on top of the system memory API. Depending on the OS and preferences of the library authors it may not ever release memory back to the OS.

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    31

    Re: problem with memory alocation

    Can you display a report with leaks?
    Last edited by Jokeman; Dec 13th, 2012 at 06:34 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    9

    Re: problem with memory alocation

    #include <list>
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>

    using namespace std;

    int main(int argc, char *argv[])
    {
    {
    printf ("Allocating\n");
    list<char*> testList;
    for (int a = 0; a < 500 * 16; a++)
    {
    char *test = new char[1024 * 64];
    memset(test, 'A', 1024 * 64);
    testList.push_back(test);
    }
    usleep(10000000);

    printf ("Deallocating\n");
    for (list<char*>::iterator a = testList.begin(); a != testList.end(); a++)
    {
    delete[] *a;
    }
    }

    usleep(10000000);

    return 0;
    }
    Hi, debagger does not show any memory leaks in this case. I check memory usage in 'top' processes list.

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    31

    Re: problem with memory alocation

    I see, if debugger does not report any memory leak, you shouldn't worry? As mentioned above, the std::list might maintain some extra data released by OS at exit. Also, not sure if top is the best choice for memory profiling..

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    9

    Re: problem with memory alocation

    I checked several times. I'm pretty sure there is a leak.

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: problem with memory alocation

    Why not run it with Valgrind to find out if there is a problem or not?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9
    Junior Member
    Join Date
    Mar 2012
    Posts
    31

    Re: problem with memory alocation

    Atheist, you're right.
    Valgrind can help you Angry100500 - this is the most reliable tool for Linux. For windows you can use purify, memcheck, deleaker, vld... Check your code! Then you'll know where is undeleted object

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    9

    Re: problem with memory alocation

    I checked the code, but the report does not contain any leakage.

  11. #11
    Member
    Join Date
    Apr 2012
    Posts
    35

    Re: problem with memory alocation

    I think it would be useful to read about a problem similar to yours. Perhaps here you will find the answers?
    http://compgroups.net/comp.unix.prog...-that-o/142500

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    9

    Re: problem with memory alocation

    Thank you. But I can not find the leak!

  13. #13
    Junior Member
    Join Date
    Mar 2012
    Posts
    31

    Re: problem with memory alocation

    Perhaps there is some discrepancy between the size of the array and the memory that is allocated for it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width