Explain the memory structure in Java. Where are objects and local variables stored, and how does garbage collection impact performance?