C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 5th, 2005, 02:35 PM
drayel drayel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 21 drayel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 59 m
Reputation Power: 0
Post Deallocate Dynamically-declared array

How can you do this? I have tried

delete state[];

and

delete []state;

and

for (i=0; i < number; i++)
state[i] = 0;
delete state[i];

What am I doing wrong?

Reply With Quote
  #2  
Old July 5th, 2005, 11:55 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
state = new char[x];
delete state[];

^^ That's what it should look like. What makes you sure that it is indeed not being deallocated?
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #3  
Old July 6th, 2005, 12:11 PM
drayel drayel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 21 drayel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 59 m
Reputation Power: 0
I get a weird error in the destructor (that's where I am deallocating the memory). I'll try it again and post the exact code and the exact error.

Reply With Quote
  #4  
Old July 8th, 2005, 06:35 PM
nishivision nishivision is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 12 nishivision User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
If you have declared the state as a dynamically, then just write free(state)
or if u have written the function - delete for deleting then just pass the state as a parameter.

Reply With Quote
  #5  
Old July 8th, 2005, 06:37 PM
nishivision nishivision is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 12 nishivision User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
hey r u there?
still having the probelm?
If you have declared the state as a dynamically, then just write free(state)
or if u have written the function - delete for deleting then just pass the state as a parameter.

Reply With Quote
  #6  
Old July 8th, 2005, 06:46 PM
nishivision nishivision is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 12 nishivision User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
can u type the whole code?

Reply With Quote
  #7  
Old July 8th, 2005, 06:46 PM
nishivision nishivision is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 12 nishivision User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
if the state is a pointer then it would work i have done that

Reply With Quote
  #8  
Old July 8th, 2005, 06:58 PM
nishivision nishivision is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 12 nishivision User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 58 sec
Reputation Power: 0
hey r u using c++?
then u have to delete the state and then write state = null;

Reply With Quote
  #9  
Old July 10th, 2005, 08:46 PM
netytan's Avatar
netytan netytan is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Knighton, UK
Posts: 29 netytan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 44 sec
Reputation Power: 0
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Isn't the same true of C as-well as C++. The memory is freed so it can be reused by the program but until the memory is written over the old value exists .

Mark.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Deallocate Dynamically-declared array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT