help-octave
[Top][All Lists]
Advanced

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

Re: private scope data destruction, or GC; How it works?


From: Olaf Till
Subject: Re: private scope data destruction, or GC; How it works?
Date: Fri, 20 Jan 2017 10:08:54 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Jan 19, 2017 at 04:22:38PM -0800, hale812 wrote:
> BTW, do CG deallocates all such arrays after exiting the function? I mean,
> if I make a copy of the output data with simple out=temp;, or "for
> i=1:length(temp); out(i)=temp(i);", should it be cleaned?

Only the returned arrays are kept, the others are cleaned. And a
simple copy with 'array2 = array1' does not need additional memory for
the data at all.

But as said, for the arrays that are kept, more memory then
corresponding to their data may be kept, if the arrays originate from
a larger array by an indexing operation. I'm not sure, but a
workaround that prevents this could be using a cat operation:

function returned_array = example_function ()

  large_array = rand (1, 1000000)

  small_array = large_array(1:1000);

  returned_array = horzcat (small_array, []);

endfunction

data = example_function (); # only necessary memory should be occupied

Olaf

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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