Cireeltsige
New Member
If an image is created via \[code\]var img=new Image()\[/code\], an \[code\]onload\[/code\] handler is added and \[code\]img.src\[/code\] is set, the image data will be requested, and \[code\]onload\[/code\] called despite the image is not attached to the DOM tree. Eg.\[code\]var img=new Image();img.onload=function(){ alert('Loaded!');}img.src='http://stackoverflow.com/questions/15736501/test.png';\[/code\]When and how this image is garbage collected? Is JavaScript capable of knowing that the \[code\]onload\[/code\]handler will be called, and called only once, to free the image afterwards? Will JavaScript notice if \[code\]img.src\[/code\] is not set and thus \[code\]onload\[/code\] will never be called and \[code\]img\[/code\]can be freed immediately?