Error Using new & delete in class 
Author Message
 Error Using new & delete in class

Need urgent assistance. when in distractor of a class I am using delete
or free to free memory that was allocated in the constructor during an
class operation, I am getting an error.

Does anyone have an answer to this problem?? If so, please email it to
me and
tell me how to fix it..
?
?
?



Tue, 14 Mar 2000 03:00:00 GMT  
 Error Using new & delete in class

Quote:

> Need urgent assistance. when in distractor of a class I am using
> delete
> or free to free memory that was allocated in the constructor during an

> class operation, I am getting an error.

Please post a snip of code and the error message to the newsgroup.

Quote:
> Does anyone have an answer to this problem?

Anybody could think of hundreds. Please understand they won't help you.

  --  Phlip
====== http://users.deltanet.com/~tegan/home.html ======
  My web page now contains 15 pages of original comics; many many more
are on the way. Whatever you think they are like (sci fi, action,
super-hero, etc),
they are not.



Tue, 14 Mar 2000 03:00:00 GMT  
 Error Using new & delete in class

 hi amir.

Quote:
>Need urgent assistance. when in distractor of a class I am using delete
>or free to free memory that was allocated in the constructor during an
>class operation, I am getting an error.

pls. post a sample that shows your problem so we can take a look at it.

WM_HOPETHISHELPS
thomas woelfer
http://www.woelfer.com
[if you post a reply, kindly refrain from emailing it, too]



Tue, 14 Mar 2000 03:00:00 GMT  
 Error Using new & delete in class

As the others said, please post code.  In the meantime, a couple of
tips:

1.  Use "free" only to release memory allocated with "malloc" or
"calloc"; use "delete" only to release non-array objects allocated with
"new"; use "delete[]" only to release arrays allocated with "new".

2.  Always make sure to initialize pointers to NULL unless you can
guarantee that they will ALL be pointed to valid, allocated memory.

HTH

Quote:

> Need urgent assistance. when in distractor of a class I am using
> delete
> or free to free memory that was allocated in the constructor during an
> class operation, I am getting an error.

> Does anyone have an answer to this problem?  If so, please email it to
> me and
> tell me how to fix it..

-- Aaron

---------------------------------
Aaron J Margosis
LCC International

Work phone:  703-873-2622 (703-USE-A-MAC ??!!)



Tue, 14 Mar 2000 03:00:00 GMT  
 Error Using new & delete in class

Actually, it's always safe to delete a NULL pointer.  But the point is a
good one.

Quote:



> writes
> >Need urgent assistance. when in distractor of a class I am using
> delete
> >or free to free memory that was allocated in the constructor during
> an
> >class operation, I am getting an error.

> >Does anyone have an answer to this problem?  If so, please email it
> to
> >me and
> >tell me how to fix it..

> I can't really say without seeing the code or error messages, but a
> problem often occurs when trying to delete null/invalid pointers.

> It helps if you ensure the pointer's null at the start of the
> constructor by doing something like -

>                 pMyPointer = NULL;

> Do this before you allocate it with new.

> In your destructor, then check the pointer before deleteing, ie -

>                 if (pMyPointer != NULL) delete pMyPointer;

> This is guesswork, given what I know about the problem, but it just
> may
> be that you're allocation has failed, or you're reallocating somewhere
> else.

> If I delete pointers elsewhere in code, I always try to remember to
> set
> the pointer to NULL again.

> Of course it could be that the pointer's getting corrupted elsewhere,
> in
> which case it's a bit more complicated.
> --
> Gordon Ansell

> Remove '.nospam' from end of e-mail address to reply.
> Know anything about pop music? Try http:\\www.di-soft.demon.co.uk

-- Aaron
---------------------
Aaron J Margosis

ScrnSaveSwitch/Plus - Screen Saver Control Utility:
http://members.aol.com/aaronmarg/ssswitch/


Fri, 24 Mar 2000 03:00:00 GMT  
 Error Using new & delete in class

delete (or free) on a zero pointer is just fine and does
*nothing* (except of course a needles function call).

but as you mentioned you really *should* set the pointer
to zero if freed/deleted ...  -(;>

Quote:
> It helps if you ensure the pointer's null at the start of the
> constructor by doing something like -

>                 pMyPointer = NULL;

> Do this before you allocate it with new.

> In your destructor, then check the pointer before deleteing, ie -

>                 if (pMyPointer != NULL) delete pMyPointer;

> This is guesswork, given what I know about the problem, but it just may
> be that you're allocation has failed, or you're reallocating somewhere
> else.

> If I delete pointers elsewhere in code, I always try to remember to set
> the pointer to NULL again.



Fri, 24 Mar 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. error when using delete & new in class

2. disappearing class view & disabled insert new class

3. new & delete

4. new&delete in different threads

5. new&delete - DLL with own heap...

6. new & delete on arrays

7. Overloading new & delete

8. new/delete operator & multithread

9. Use of new & delete

10. new & delete

11. new&delete in different threads

12. new&delete - DLL with own heap...

 

 
Powered by phpBB® Forum Software