Skip to main content
GameDev.net gamedev.net
🔒 Locked

Deleting array[var1][var2]

Started by G-riff Apr 19, 2004 at 9:23 PM 4 replies 550+ views
Original Post
G-riff
G-riff
Could someone please let me know how to delete an array that was initialized like this: int array[var1][var2] where var1 and var2 are sizes? If I try to delete it like this:
for(int i=0; i < var2; i++)
       delete [] array[i];
delete [] array;
 
it doesn't compile. What am I doing wrong? Thanks to whomever replies. edit: fixed your formatting [edited by - SiCrane on April 19, 2004 10:28:29 PM]
SiCrane
SiCrane
The notation you used for declaring your array is for static or stack allocation. In that case, you don''t need to call delete on it.
G-riff
G-riff
Thank you for your timely response. So I don''t have to delete it at all? I am extensively testing the program that this is in and I wanted to make sure that it wouldn''t take up any space after I had used it.
SiCrane
SiCrane
Whether or not it takes up space after you''ve used it depends on where you''ve declared it. If it''s a global variable it''s going to take up space throughout the entire program. If it''s a local function variable it will get reclaimed when the function returns.
rsegal
rsegal
quote:

Thank you for your timely response. So I don''t have to delete it at all?


Nope, you only need to delete when you allocate memory with new. And make sure you know which delete you should be calling, either "delete" or "delete []" for arrays!
Rob Segal - Software Developerrob@sarcasticcoder.com
G-riff
G-riff
Ok, thanks again for clearing that up.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.