Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

memory deallocation for local objects

Former Member
0 Likes
1,184

Hi Gurus, i have a silly doubt

If i declare 100 local objects in my subroutine.

Those objects will be allocated memory wen the subroutine is run.

When i leave the subroutine, will the memory be deallocated for all those local objects? or will it just clear the memory ?

And if i call the subroutines multiple times, will an allocation happen every time?

thanks in advance.

6 REPLIES 6
Read only

matt
Active Contributor
0 Likes
1,099

This is a great opportunity for you to use the memory analyser in debug. Write an example program, then debug it and use that memory analyser tool. See what happens. And report back.

I hope you're able to do this before someone spoonfeeds you the answer!

Read only

Former Member
0 Likes
1,099

i tried as you said and i observed that memory for all local variables are released after the control comes out of the subroutine.

So will it negatively impact the performance of my program if i call a subroutine with too many local declarations inside a loop, cause of the allocation process .  Is it better to declare them globally?

Read only

matt
Active Contributor
0 Likes
1,099

First of all, declarations are super fast, so there really is no performance hit of any consequence. Second - and learn this mantra - LOCAL GOOD, GLOBAL BAD.

The number of global variables must be kept at an absolute minimum. This is good programming practice and will make your programs more robust. Also, if you have many local declarations in a subroutine then that is an indication that you should modularise further - i.e. make more subroutines.

Communicate between subroutines using parameters.

Except for a few places, as a good programmer you should worry far more about your program design, maintainability and readability than performance. Only break good programming when squeezing the last dribble of performance is an absolute requirement.

Read only

Former Member
0 Likes
1,099

Thanks a lot Mathew ,

That's all i wanted to know,will keep in mind

and I can't find the 'Correct answer button'

Read only

matt
Active Contributor
0 Likes
1,099

That's because this is a discussion rather than a question.

Read only

SwadhinGhatuary
Active Contributor
0 Likes
1,099

Hi Rojer,

when ever control come out of form..endform what ever variable,constant are declared inside are memory deallocated .  

Have a look on this