Memory Leak
-
I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.
-
I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.
rr_ramesh71 wrote:
I have some array member
What kind of array it is ?
-
I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.
How are the arrays declared? If they're declared as local variables (as shown with
localArray
below), they will definitely be cleared up, as they're allocated space on the stack, which is tidied up when the function exits.double SomeFunction(int x)
{
double localArray[] = { 1.0, 2.0, 3.0, 4.0 };
const size_t localArraySize = sizeof localArray / sizeof localArray[0];
return x<localArraySize?localArray[x]:-1.0;
} -
I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.
The only thing you have to take care in this case, is that if you are allocating memory with new (or new[]), then you should delete it with delete (or delete[]). For the rest, the memory will be automatically released.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
rr_ramesh71 wrote:
I have some array member
What kind of array it is ?
char lbuffer[5000]; // will this array get released after the function over
sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
-
The only thing you have to take care in this case, is that if you are allocating memory with new (or new[]), then you should delete it with delete (or delete[]). For the rest, the memory will be automatically released.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Also don't forget malloc and free (I know, i know, don't use malloc and free in C++ but they CAN be used), and maybe GlobalAlloc and GlobalFree (or LocalAlloc and LocalFree but as far as i know those are no longer different from their Global counterparts)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
char lbuffer[5000]; // will this array get released after the function over
sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
Yes the buffer will be released.
rr_ramesh71 wrote:
but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
How do you check that ? Are you using some tools to verify that information ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
char lbuffer[5000]; // will this array get released after the function over
sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed
rr_ramesh71 wrote:
// will this array get released after the function over
Yes, You don't need to worry about memory, as its been allocated on stack.