Adam Outler wrote:In option 2, the log class is created and destroyed as needed, leading to possible speedup of certain code and logging operations require the additional step of instatiating a new class. Memory is saved and certain code executes quicker.
Paul Clapham wrote:Edit: Wait, sorry, it isn't a static method. You just used a non-standard naming convention which caused me to believe it was. Did somebody already mention readability in this thread?
Adam Outler wrote:my program uses 500 megs of memory.
Ok, I thought I would try to reduce things where i could. That makes sense.Paul Clapham wrote:
Adam Outler wrote:my program uses 500 megs of memory.
If your program uses 500 megs then there's no point fussing over the odd logger object here and there. That would be like removing your closet doors so that you had more floor space. (Well, you would. Each door covers about 300 square centimetres of floor space.) Or like removing your front door so that you could get to work faster. (Well, you would. It takes you a couple of seconds to open, close, and lock the door.)
But seriously, if you want to remove memory usage then find out what is using the memory. Don't choose random stuff, profile your code to see what is actually using the memory.
Paul Clapham wrote:
Adam Outler wrote:In option 2, the log class is created and destroyed as needed, leading to possible speedup of certain code and logging operations require the additional step of instatiating a new class. Memory is saved and certain code executes quicker.
No, that's completely wrong. Once a class is loaded, it never gets unloaded. If you had made that statement about objects instead of classes, then some parts of it would be correct. The parts about speedup of code and saving of memory are still just unsupported speculation, though.
Adam Outler wrote:So you're saying that the memory manager never cleans up unused classes? how do I destroy them after creation.... Like... I press a button, that launches a method which creates 6 class objects and uses their methods as a separate thread... What then? They just hang around in memory and when I hit the button again another 6 are created?
This is a VERY direct question now.... What's a best practice here? Generate a class object at the highest level for ease of use, or generate a class object at the lowest level possible?
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|