• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about the heap and memory

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic