‎2015 Jun 24 8:08 PM
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.
‎2015 Jun 25 6:41 AM
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!
‎2015 Jun 25 12:08 PM
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?
‎2015 Jun 25 3:24 PM
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.
‎2015 Jun 25 4:21 PM
Thanks a lot Mathew ,
That's all i wanted to know,will keep in mind
and I can't find the 'Correct answer button'
‎2015 Jun 25 5:29 PM
‎2015 Jun 25 10:11 AM
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