Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:38:17+00:00 2026-05-15T14:38:17+00:00

Why do we use Heap Memory, Can we use Stack memory for the same?

  • 0

Why do we use Heap Memory, Can we use Stack memory for the same?


EDITED

One more question came in my mind after reading answers
1) is there any other kind of memory which we can think of alternative to Heap and Stack?


Edited

I came across the string pool, is that memory associated with the heap or Stack?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:38:18+00:00Added an answer on May 15, 2026 at 2:38 pm

    Well, you have to use the heap if you want to use objects. Objects are inherently pointers on the stack (or inside other objects) to memory chunks in the heap.

    Unlike C++ where you can put objects on the stack or heap, Java does things differently.

    Even in C++, it’s a good idea to use the heap for objects that must outlive the function they were created in. You probably can avoid it but you may find yourself with a performance problem with all the copy constructors.


    As to your edit:

    Is there any other kind of memory which we can think of alternative to Heap and Stack?

    Sure there is: Static data members, the ones where there’s only one per class rather than one per instantiated object must go somewhere. These can’t be on the stack since they may disappear when you exit from a function. And they can’t belong to an particular object.

    These (at least in the Sun/Oracle JVM) go into the Method area.

    In addition, you should not think of there being one stack. Every thread gets its own stack on creation.

    There’s also the runtime constant pool and stacks for native (non-Java) calls.

    There’s lots of information on the JVM internals here regarding that aspect but keep in mind there may be a distinction between the logical machine and the implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every process can use heap memory to store and share data within the process.
Question Can we use move semantics to move a heap allocated object on the
I was reading this article on MSDN Managing Heap Memory in Win32 And in
A block of memory can be allocated statically, in the stack or in the
I've been creating a temporary object stack- mainly for the use of heap-based STL
Possible Duplicate: When is it best to use a Stack instead of a Heap
I'm trying to use Haskells Data.Heap module, but I'm incapable of even using it
I have a vector that I want to use to create a heap. I'm
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;
Ok, I've been reading everything I can find on var, and I'm pretty sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.