java - Resource Leak (Resource out of scope) -


hi here couple of lines in code.

func(){ .... ....  objectinputstream in = xstream.createobjectinputstream(is); return (useraccountvo)in.readobject(); } 

now giving warning "leaked_resource: variable in going out of scope leaks resource refers to".

can please explain it?

and 1 more point. how got fixed via this:

try(objectinputstream in = xstream.createobjectinputstream(is);) {                     return (useraccountvo)in.readobject();                 } catch (ioexception e) {                     s_logger.error(e.getmessage());                     return null; } 

in former case, not closing resource 'in' , may result in memory leak. therefore warning. while in later case, have put 'in' instantiation within try block adds implicit 'finally' close resource.

hope clarifies.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -