[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

clearing intermediate variables at end of functions?

From: Rik
Subject: clearing intermediate variables at end of functions?
Date: Fri, 29 Aug 2014 09:35:06 -0700



I was just cleaning up nchoosek.m and I came across this construct at the
end of the function:

--- Begin Code ---
    clear cA b;
    C = C.';

--- End Code ---

Is there any reason why it should be necessary to clear the intermediate
variables cA and b manually?  They are local to the m-file and as soon as
the endfunction is hit they will go out of scope and the memory should be
reclaimed.  I thought maybe, just maybe, it was because they were large and
the original programmer was worried that the transpose operation was going
to create an intermediate copy of C.  But this shouldn't be the case,
should it?  Don't we do something intelligent like simply reverse the row,
column attributes on the existing C matrix rather than creating a full
blown copy?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]