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

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - On Gitbash - Bower : ENOGIT git is not installed or not in the PATH -