Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Clear function local variable?
Replies: 3   Last Post: Jun 19, 2013 11:15 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Luca Balbi

Posts: 12
Registered: 4/17/09
Clear function local variable?
Posted: Jun 19, 2013 2:49 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello,
sorry if this was answered before but I can't seem to find a known answer.
Several times I have seen that inside a function a local variable is cleared, like this:
(I know it's a silly example, it's just an example... :D )
function [] = foo(a)
% ...
x = a.^2; % x is local to foo, not global
y = 2 * x;
clear x;
% ...
end %function

Unless x is veeeeeeery big in memory, this seems pointless to me: x gets out of scope and is cleared at the function end.
The question is: is clearing local variables as soon as they are no longer useful a good practice?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.