memory allocation problems

Discussion in 'C++' started by Kieran Simpson, Jun 30, 2003.

  1. In my project I have a class which I create an instance of, into a pointer
    using the 'new' keyword.

    Inside 'class1' I allocate memory (using malloc) for a string in the
    constructor and everything works fine. When I try to destroy the instance
    using the corresponding 'delete' keyword, the code goes to 'class1'
    destructor where I try to free the memory (using free) allocated by the
    constructor. However I get a debug error.

    Am I getting the error because when I destroy the instance of 'class1' the
    memory allocated by the constructor is already freed, and therefore I am
    trying to free free memory, or is there something else at work?
     
    Kieran Simpson, Jun 30, 2003
    #1
    1. Advertising

  2. Kieran Simpson

    Jason Xie Guest

    before you free the memory, please check that it is not a null pointer.

    Jasn

    "Kieran Simpson" <> дÈëÏûÏ¢ÐÂÎÅ
    :kPLLa.37$...
    > In my project I have a class which I create an instance of, into a pointer
     
    Jason Xie, Jun 30, 2003
    #2
    1. Advertising

  3. "Jason Xie" <> wrote in message
    news:bdobfo$rnq$...
    > before you free the memory, please check that it is not a null pointer.


    Freeing a NULL pointer does not cause any problems.
    OP should post some real code to demonstarate the problem.
     
    Josephine Schafer, Jun 30, 2003
    #3
  4. "Kieran Simpson" <> wrote in message
    news:kPLLa.37$...
    > In my project I have a class which I create an instance of, into a pointer
    > using the 'new' keyword.
    >
    > Inside 'class1' I allocate memory (using malloc) for a string in the
    > constructor and everything works fine. When I try to destroy the instance
    > using the corresponding 'delete' keyword, the code goes to 'class1'
    > destructor where I try to free the memory (using free) allocated by the
    > constructor. However I get a debug error.
    >
    > Am I getting the error because when I destroy the instance of 'class1' the
    > memory allocated by the constructor is already freed, and therefore I am
    > trying to free free memory, or is there something else at work?
    >


    Maybe, maybe not. Hard to tell without seeing any code.

    POST SOME CODE, jeez.

    john
     
    John Harrison, Jun 30, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. s.subbarayan

    Dynamic memory allocation and memory leak...

    s.subbarayan, Mar 18, 2005, in forum: C Programming
    Replies:
    10
    Views:
    720
    Eric Sosman
    Mar 22, 2005
  2. Rodrigo Dominguez

    memory allocation and freeing memory

    Rodrigo Dominguez, Jun 13, 2005, in forum: C Programming
    Replies:
    11
    Views:
    616
    Jean-Claude Arbaut
    Jun 15, 2005
  3. Ken
    Replies:
    24
    Views:
    3,896
    Ben Bacarisse
    Nov 30, 2006
  4. chris
    Replies:
    6
    Views:
    1,007
    chris
    Oct 28, 2005
  5. Bjarke Hammersholt Roune
    Replies:
    14
    Views:
    1,207
    Bjarke Hammersholt Roune
    Mar 6, 2011
Loading...

Share This Page