memory leak , help please?

This is a discussion on memory leak , help please? within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> #include <string> #include <deque> using namespace std; #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> struct myStruct { int i; string str; ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    19

    Unhappy memory leak , help please?

    #include <iostream>
    #include <string>
    #include <deque>
    using namespace std;

    #define _CRTDBG_MAP_ALLOC
    #include <crtdbg.h>

    struct myStruct
    {
    int i;
    string str;
    };

    int main()
    {
    deque <myStruct*> mine;
    _crtBreakAlloc=-1;

    myStruct* s;
    for (int i =0 ; i < 10 ; i ++)
    {
    s = new myStruct;
    s->i = i;
    s->str = "hello" +i;

    mine.push_back(s);
    //delete s;
    }

    for (int i = 0; i < mine.size() ; i++)
    cout << mine[i]->i << endl;

    system( "pause" );
    }

    as you can see its very simple . if i use the "delete s" then it will stop the memory leaks but will also make everything in mine compleatly random .

    can anyone help , or give me a link or book name to find how to fix this please

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    Quote Originally Posted by thedodgeruk View Post
    can anyone help
    Sure they can

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leak in this case?
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 03-22-2008, 06:05 AM
  2. memory leak in the code?
    By George2 in forum C++ Programming
    Replies: 20
    Last Post: 01-13-2008, 06:50 AM
  3. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 04:19 PM
  4. Any Memory Leak Checking Tool?
    By George2 in forum C Programming
    Replies: 4
    Last Post: 06-22-2006, 12:02 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 10:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21