Here's what I am trying to determine...
I have a utility class to append lines to a textfile. This must be used by a number of other classes, like a common logging file.
In my first implementation, I had all the classes that wanted to use it make a referenceless instance, e.g.
new Logger(logline,logname);
The constructor creates a PrintWriter, appends the line and closes the file.
This seemed wasteful, since a new instance gets made for every line appended.
The alternative was to use a static method, called "writeln" in this common class, since I had understood that static methods and data re-use the same memory over & over...but
this static method creates an instance of PrintWriter to do its job, so doesn't that mean that a new instance of PrintWriter is created for every line, like #1?
Anyway, (I am relatively new to Java ) is there a well-known, approved way of doing this, or do we just create away, and let the garbage-collector clean up after us?
Thanks,