What is the difference between heap and stack

1.heap is the heap, and stack is the stack. 2. The stack space is automatically allocated and released by the operating system , and the heap space is manually applied and released. The heap is often allocated with the new keyword. 3. The stack space is limited, and the heap space is a large free area. In Java, if you just declare an object, first allocate its address space in stack memory, and if you new and instantiate it, then allocate its address in heap memory. 4. Example: data type variable name; things defined in this way are in the stack area. Such as: Object a =null; only allocate space in stack memory new data type(); or malloc(length); Such defined things are in the heap area such as: Object b =new Object(); Then allocate in heap memory space

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326264694&siteId=291194637