• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about the heap and memory  RSS feed

 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a problem now where I can hide every single variable inside the methods that actually use that variable. The conundrum I'm in is this. One of my methods is called multiple times and, if a certain value is not passed, will create some String arrays. If I'm understanding the way the heap works, these objects are doomed once my method completes.

I could just as easily move them out of the method and make them global, and I keep looking at it, moving them back and forth. One part says "Why initialize them over and over?" and the other part says "if that certain condition is passed you'd never need them anyway!". I'm leaning more towards only having them created once as I can just imagine a bunch of objects wallowing in null-dom, but I'd also like to get more seasoned opinions as well.

Thanks in advance,
Nate
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, i'd worry less about how often they get created/wallowing in "null-dom", and more about what makes more sense.

remember that in 2 months or year, you (or someone else) will be coming back to revise this code, and are gonna have to figure out what it is doing. design it in the simplest, easiest to understand way. THEN, if there is a performance issue, look at how to revise your design.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!