
Hi programmers, Eclipse complains about a lot places in the source code., e.g. "Resource leak: 'fmt' is never closed SyntaxException.java /mkgmap/src/uk/me/parabola/mkgmap/scan line 45 Java Problem" The code looks like this: public String getMessage() { Formatter fmt = new Formatter(); fmt.format("Error: "); if (fileName != null) fmt.format("(%s:%d): ", fileName, lineNumber); fmt.format(super.getMessage()); return fmt.toString(); } The message disappears if I change the last line to this: String res = fmt.toString(); fmt.close(); return res; Does anybody know if this can really improve something? Gerd

Hi
Eclipse complains about a lot places in the source code., e.g. "Resource leak: 'fmt' is never closed SyntaxException.java /mkgmap/src/uk/me/parabola/mkgmap/scan line 45 Java Problem"
The code looks like this:
public String getMessage() { Formatter fmt = new Formatter();
In this case it writes to a StringBuilder. This is not even a Closable, so the close() method of Formatter does nothing in this case. So nothing is being leaked. ..Steve

Hi Steve, yes, I agree. I've also tried a test code and found no reason for the message from Eclipse. It just complains about all closable instances which are not explicitely closed. I think most of them can be ignored. It's just that I wonder why mkgmap requires more and more memory the longer that it runs, so I started to check all these messages about resource leaks. The longer it runs, the longer it takes to do a Full GC. Found nothing important so far. Gerd Steve Ratcliffe wrote
Hi
Eclipse complains about a lot places in the source code., e.g. "Resource leak: 'fmt' is never closed SyntaxException.java /mkgmap/src/uk/me/parabola/mkgmap/scan line 45 Java Problem"
The code looks like this:
public String getMessage() { Formatter fmt = new Formatter();
In this case it writes to a StringBuilder. This is not even a Closable, so the close() method of Formatter does nothing in this case.
So nothing is being leaked.
..Steve _______________________________________________ mkgmap-dev mailing list
mkgmap-dev@.org
-- View this message in context: http://gis.19327.n5.nabble.com/Resource-leaks-tp5805378p5805408.html Sent from the Mkgmap Development mailing list archive at Nabble.com.
participants (3)
-
Gerd Petermann
-
GerdP
-
Steve Ratcliffe