Differences

This shows you the differences between two versions of the page.

Link to this comparison view

guidelines:memory_leaks [2011/12/22 15:10]
michal.bida created
guidelines:memory_leaks [2013/01/23 15:15] (current)
jakub.gemrot
Line 3: Line 3:
 Why to talk about memory leaks in Java? You who do not know the answer, consider following scenerio that is likely to happen to those, who do not know the answer on previous question ;-) Why to talk about memory leaks in Java? You who do not know the answer, consider following scenerio that is likely to happen to those, who do not know the answer on previous question ;-)
  
-You have your uber-object A that you're using quite frequently and you need it to listen on some events. Great - let's create an anonymous object B inside your object and hook it to whatever event E you want. Okey, program continues, everything is fine. Well, everything has an end, so is the usefullnes of your uber-object A. You're in Java, you just drops the reference onto the uber-object A with hope that GC will clean the mess after you ... Your hope is false... there is that little devil - anonymous listener B that is keeping the reference to the uber-object A and the 'event queue' of E that is holding the reference to that anonymous object B. So the uber-objet A is still strongly reachable. ​ Damn... we're losing memory here! Not mentioning the mess the uber-object A may still cause.+You have your uber-object A that you're using quite frequently and you need it to listen on some events. Great - let's create an anonymous object B inside your object and hook it to whatever event E you want. Okey, program continues, everything is fine. Well, everything has an end, so is the usefullnes of your uber-object A. You're in Java, you just drop the reference onto the uber-object A with hope that GC will clean the mess after you ... Your hope is false... there is that little devil - anonymous listener B that is keeping the reference to the uber-object A and the 'event queue' of E that is holding the reference to that anonymous object B. So the uber-objet A is still strongly reachable. ​ Damn... we're losing memory here! Not mentioning the mess the uber-object A may still cause.
  
 So what is the answer? Weak / Phantom references... is that the salvation? If you are disciplined enough and have a great foresight. So it's likely not, but close enough :-) So what is the answer? Weak / Phantom references... is that the salvation? If you are disciplined enough and have a great foresight. So it's likely not, but close enough :-)
guidelines/memory_leaks.txt · Last modified: 2013/01/23 15:15 by jakub.gemrot