Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > memory allocation problems

Reply
Thread Tools

memory allocation problems

 
 
Kieran Simpson
Guest
Posts: n/a
 
      06-30-2003
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?


 
Reply With Quote
 
 
 
 
Jason Xie
Guest
Posts: n/a
 
      06-30-2003
before you free the memory, please check that it is not a null pointer.

Jasn

"Kieran Simpson" <(E-Mail Removed)> 写入消息新闻
:kPLLa.37$(E-Mail Removed)...
> In my project I have a class which I create an instance of, into a pointer




 
Reply With Quote
 
 
 
 
Josephine Schafer
Guest
Posts: n/a
 
      06-30-2003

"Jason Xie" <(E-Mail Removed)> wrote in message
news:bdobfo$rnq$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      06-30-2003

"Kieran Simpson" <(E-Mail Removed)> wrote in message
news:kPLLa.37$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An idea for heap allocation at near stack allocation speed Bjarke Hammersholt Roune C++ 14 03-06-2011 08:07 AM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
memory allocation and freeing memory Rodrigo Dominguez C Programming 11 06-14-2005 11:54 PM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM



Advertisments