Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question for the C++ gurus
Message
De
13/05/2000 13:49:44
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00368531
Message ID:
00369357
Vues:
25
>Does using the keyword "new" automatically put the object on the heap?

Yes.

>Before function ends, I have to delete pointer to deallocate memory used by object?

You are not deleting the pointer. You are telling the heap manager to free the memory block referenced by the pointer. The pointer itself is often allocated on the stack. Also make sure you do the appropriate delete for the type of new.

From C++ Primer Plus, Third Edition by Stephen Prata, Copyright 1998 by Sams publishing:

Don't use delete to free memory that new didn't allocate.
Don't use delete to free the same block of memory twice in succession.
Use delete [] if you used new [] to allocate an array.
Use delete (no brackets) if you used new to allocate a single entity.
It is safe to apply delete to the null pointer (nothing happens).

>If I didn't, would it automatically be deleted when object reference goes out of scope when function ends?

No, only objects created on the stack are automatically deleted when the object reference goes out of scope.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform