Delete local : good practice
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Delete local : good practice
I use LiveCode with a database from which I pull off thousands of records.
I started to look around "delete local", in order to clean up the memory.
What is the best practice ?
To declare :
local myVar
delete local myVar
at the beginning of my handler.
Or at the end, when I don't need the variable anymore ?
Or both ?
Something bothers me. I read in the dictionnary " Local variables that are used within a handler are automatically deleted when the handler in which they are used exits."
However, in the compiled version of my app, I've noticed after doing many queries that the memory used is increasing. That contradicts what is written in the dictionnary, no ?
I started to look around "delete local", in order to clean up the memory.
What is the best practice ?
To declare :
local myVar
delete local myVar
at the beginning of my handler.
Or at the end, when I don't need the variable anymore ?
Or both ?
Something bothers me. I read in the dictionnary " Local variables that are used within a handler are automatically deleted when the handler in which they are used exits."
However, in the compiled version of my app, I've noticed after doing many queries that the memory used is increasing. That contradicts what is written in the dictionnary, no ?
Re: Delete local : good practice
Hi bangkok,
Best
Jean-Marc
I think that is for local variable without declaringSomething bothers me. I read in the dictionnary " Local variables that are used within a handler are automatically deleted when the handler in which they are used exits."
Best
Jean-Marc
https://alternatic.ch
Re: Delete local : good practice
Hi bangkok,
a script <> a handler!
A script can consist of more than one handler and/or function.
So any (un-declared) local variable is being forgotten after the handler has finished:
I would simply EMPTY local variables instead of deleting them.
Best
Klaus
a script <> a handler!
A script can consist of more than one handler and/or function.
So any (un-declared) local variable is being forgotten after the handler has finished:
Code: Select all
on mouseup
put 10 into tWhatever
answer tWahtever
end mouseup
## At this point, tWhatever is history :D
Best
Klaus
Re: Delete local : good practice
I'm really confused.Klaus wrote: A script can consist of more than one handler and/or function.
So any (un-declared) local variable is being forgotten after the handler has finished:I would simply EMPTY local variables instead of deleting them.Code: Select all
on mouseup put 10 into tWhatever answer tWahtever end mouseup ## At this point, tWhatever is history :D
In my script, with a mouseup, I read large quantity of data. It goes into a variable. This var is not declared. So following what you say, at the "end mouseup" it would be cleared from memory, right ?
In my compiled application, this is not what I saw (via CTRL ALT DEL). The more i clicked on the button, the more the memory used by the application increased.
This is why, I started to look around about this issue. And then I changed the script with a "local var" followed by a "delete local var" at the beginning of the script. I
I made the test again. The memory used stayed constant.
Re: Delete local : good practice
Hi bangkok,
If this is definitively not the case, then this should be bug-reported: bugs@runrev.com
Best
Klaus
Yep, this is how it is supposed to be, I never examined this for correctnessbangkok wrote:...In my script, with a mouseup, I read large quantity of data. It goes into a variable. This var is not declared. So following what you say, at the "end mouseup" it would be cleared from memory, right ?

If this is definitively not the case, then this should be bug-reported: bugs@runrev.com
Best
Klaus
Re: Delete local : good practice
Hi bangkok,
tWhatever don't exists after mouseup
and
tWhatever = 3 after mouseup
Best
Jean-Marc
For me (OSX)...In my script, with a mouseup, I read large quantity of data. It goes into a variable. This var is not declared. So following what you say, at the "end mouseup" it would be cleared from memory, right ?
Code: Select all
on mousedown
put 3 into tWhatever
end mousedown
on mouseUp
put tWhatever
end mouseUp
and
Code: Select all
local tWhatever
on mousedown
put 3 into tWhatever
end mousedown
on mouseUp
put tWhatever
end mouseUp
Best
Jean-Marc
https://alternatic.ch
Re: Delete local : good practice
Local handler variables are cleared after the handler ends. Garbage collection however doesn't occur until the next idle period, so the memory may be in use for a short time until that happens. If you have other handlers running in the background or anything else that is occupying the engine's time, it won't get around to clearing the memory until other pending messages have cleared the queue.
Another possible mistake is using the same variable name for a script-local or global variable. This is unlikely if you have explicit variables turned on in the script editor, but if you don't, then in some cases it can occur. Be sure your local handler variables are uniquely named.
Another possible mistake is using the same variable name for a script-local or global variable. This is unlikely if you have explicit variables turned on in the script editor, but if you don't, then in some cases it can occur. Be sure your local handler variables are uniquely named.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Delete local : good practice
Sorry guys... I should have told you before : i think the issue is related to Datagrids.
I'm pulling off data from a DB, and put the data into a Datagrid.
Here is a small stack, so you can test yourself. It generates large text and put it into a DG. Very simple.
Without "local myvar" and "delete local myvar"... the memory used is increasing, each time you press the button.
-create a standalone (I did my tests on Windows)
-Open the task manager in order to check the memory used by the process
-then press a dozen of times or more
I'm pulling off data from a DB, and put the data into a Datagrid.
Here is a small stack, so you can test yourself. It generates large text and put it into a DG. Very simple.
Without "local myvar" and "delete local myvar"... the memory used is increasing, each time you press the button.
-create a standalone (I did my tests on Windows)
-Open the task manager in order to check the memory used by the process
-then press a dozen of times or more
- Attachments
-
- TEST.zip
- (5.91 KiB) Downloaded 250 times
Re: Delete local : good practice
Hi bangkok,
I'll do a new topic: "get the size of a variable"
Best
Jean-Marc
Is there a way to get the size of a variable in LC (i understand you have a "task manager" for windows)Without "local myvar" and "delete local myvar"... the memory used is increasing, each time you press the button.
I'll do a new topic: "get the size of a variable"
Best
Jean-Marc
https://alternatic.ch
Re: Delete local : good practice
Hi Bangkok,
If you need know if a variable exists the syntax "there is" work also with variable
It is not in the dictionary but it work for me
Best
Jean-Marc
If you need know if a variable exists the syntax "there is" work also with variable
It is not in the dictionary but it work for me
Code: Select all
on mousedown
put 3 into tWhatever
end mousedown
on mouseUp
if there is tWhatever then
put tWhatever
else
put "tWhatever don't exists"
end if
end mouseUp
Jean-Marc
https://alternatic.ch