Close memory leaks

I'm interested in the possibility of a memory leak (unnecessary link) memory leak in garbage collection

caused by variables in closed storage (possibly as part of an object system or as part of construction activities based on input for subsequent evaluation).

Are there any languages ​​where such things are somewhat common? If so, which patterns should be monitored in these languages ​​to prevent this?

+3
source share
4 answers

As long as the link is referenced, fixed variables will be saved. As a result, you need to be careful where you create links to these closures.

, , . , - , :)

+3

, , Internet Explorer < 7 , . , , javascript .

,

function foo() {
    var div = document.getElementById('mydiv');
    div.onclick = bar;

    function bar() {
        div.style.opacity = 0.5;
    }
}

, , bar div div.

, IE .

+1

, , , , , . :

Action blah(Dictionary<string, int> dict, List<string> list)
{
  int i;
  list.ForEach( (st) => if (dict.Contains(st)) i++; );
  return () => Console.WriteLine("The value was {0}", i);
}

. dict i, . i, . , , .

, , dict int[1], int[1]; int[1], . , , , .

+1

"", , GC , . , . , .

0

All Articles