octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #62459] Severe memory leak when functions are


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #62459] Severe memory leak when functions are nested
Date: Mon, 16 May 2022 18:21:18 -0400 (EDT)

Follow-up Comment #9, bug #62459 (project octave):

@Rik: I agree with comment #8. It is something to do with "crossing the scope
boundary" for lack of a better term. This causes no leak at all:


function test_memleak
  for i = 1:10
    f(rand(1000));
  end
endfunction

function retval = f(p)
  function ret = g()
    ret = (@(x)(1 / rand(1) ./ x))(p);
  endfunction
  retval = g();
endfunction


In that version, the anonymous function is declared inside the subfunction in
such a disposable manner that when the subfunction exits it releases all
resources.

But if the anonymous function is named outside the subfunction and then used
inside it ("crossing the scope boundary"), neither party seems to realize that
they ought to release the memory, or that the memory is no longer being used
by anyone, so the overhead keeps leaking for every function invocation.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?62459>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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