By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

char array memory collection

P: 1
I'm creating a char array in the following way, and don't know whether it is being collected or not. I know I have a memory leak somewhere in my code ("ps wwvg | grep myapplication" shows memory usage) , but I'm not sure if it's being caused by the following:


Expand|Select|Wrap|Line Numbers
  1.  
  2. void example()
  3. {
  4. char array[50000]="";
  5. }
  6.  
That's basically it. Normally I would do something like

Expand|Select|Wrap|Line Numbers
  1. char * array = new char[5000];
in which case I would know to delete it, but I can't find any info on the first way of creating/deleting an array.
Aug 9 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
I'm creating a char array in the following way, and don't know whether it is being collected or not. I know I have a memory leak somewhere in my code ("ps wwvg | grep myapplication" shows memory usage) , but I'm not sure if it's being caused by the following:


Expand|Select|Wrap|Line Numbers
  1.  
  2. void example()
  3. {
  4. char array[50000]="";
  5. }
  6.  
That's basically it. Normally I would do something like

Expand|Select|Wrap|Line Numbers
  1. char * array = new char[5000];
in which case I would know to delete it, but I can't find any info on the first way of creating/deleting an array.
In your first example the array is a so called 'automatic' variable, i.e. it resides on
the stack and is 'automatically' ripped from existence when the function returns.

kind regards,

Jos
Aug 9 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
Also, be careful of large stack memory usage. Some systems limit stack to as little as 4K without negotiating with a SysAdmin for more.

Prefer the heap to the stack.
Aug 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.