heap-memory

PermGen and Heap, Difference and their significance

喜你入骨 提交于 2019-12-02 19:20:35
Friends, Can you please give me significance, difference and uses for Heap and PermGen. Also it would be good to know what class are loaded in them respectively. Explanation related to Java VM specification would be really helpful Thanks Punith Memory(Heap) is managed in generations, or memory pools holding objects of different ages. Garbage collection occurs in each generation when the generation fills up. Objects are allocated in a generation for younger objects or the young generation , and because of infant mortality most objects die there. When any new object is constructed it goes to

Java stack and heap memory management

一笑奈何 提交于 2019-12-02 14:15:30
I want to know how the memory is being allocated in the following program: public class MemoryClass { public static void main(final String[] args) { int i = 0; MemoryClass memoryClass = new MemoryClass(); memoryClass.myMethod(memoryClass); } private void myMethod(final Object obj) { int i = 1; String s = "HelloWorld!"; } } Now, as far as my understanding goes, the following diagram describes how the memory allocation takes place: In the above diagram, memory , obj and s , which are in the stack memory, are actually the references to their " actual objects " which are placed inside the heap

OutOfMemory exception in a lot of memory

耗尽温柔 提交于 2019-12-02 10:02:47
Sorry for the bad question name but i couldn't find anything better. I have some code long heapFreeSize = Runtime.getRuntime().freeMemory(); URL url = new URL("http://example.com"); URLConnection myUrlConnection = url.openConnection(); GZIPInputStream gZIPInputStream = new GZIPInputStream(myUrlConnection.getInputStream()); StringBuffer decompressedStringBuffer = new StringBuffer(); int bytes_read; int bufferSize; heapFreeSize = Runtime.getRuntime().freeMemory(); while ((bytes_read = gZIPInputStream.read(buffer)) > 0) { String part = new String(buffer, 0 ,bytes_read, "UTF-8"); heapFreeSize =

Dynamically allocating new object in constructor

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 06:12:34
问题 So given this simple scenario: class A{ public: A(){ n = new int(10); } ~A(){ delete n; } int* n; }; int main(){ A* a = new A(); } Can this cause heap corruption (problems in general), since a-pointer hasn't finished allocating, while I'm making a new allocation? If so, using std::vector inside heap constructors in also prohibited, right? Thank you. 回答1: Your a pointer has finished allocating . New works as follows (oversimplified) Allocate Construct So in your case Allocate A Construct A

Dynamically allocating new object in constructor

点点圈 提交于 2019-12-02 02:40:07
So given this simple scenario: class A{ public: A(){ n = new int(10); } ~A(){ delete n; } int* n; }; int main(){ A* a = new A(); } Can this cause heap corruption (problems in general), since a-pointer hasn't finished allocating, while I'm making a new allocation? If so, using std::vector inside heap constructors in also prohibited, right? Thank you. Your a pointer has finished allocating . New works as follows (oversimplified) Allocate Construct So in your case Allocate A Construct A Allocate int Construct int - initialize Finish Construct A This ignores cases involving exceptions.. There is

Neo4j in Docker - Max Heap Size Causes Hard crash 137

南楼画角 提交于 2019-12-01 20:09:58
I'm trying to spin up a Neo4j 3.1 instance in a Docker container (through Docker-Compose), running on OSX (El Capitan). All is well, unless I try to increase the max-heap space available to Neo above the default of 512MB. According to the docs , this can be achieved by adding the environment variable NEO4J_dbms_memory_heap_maxSize , which then causes the server wrapper script to update the neo4j.conf file accordingly. I've checked and it is being updated as one would expect. The problem is, when I run docker-compose up to spin up the container, the Neo4j instance crashes out with a 137 status

What's the difference between delete-ing a pointer and setting it to nullptr? [duplicate]

喜你入骨 提交于 2019-12-01 19:32:14
This question already has an answer here: delete vs NULL vs free in c++ 6 answers Is saying delete pointer and pointer = nullptr the same? Probably not, but does the latter free up memory? What about delete pointer; pointer = nullptr / pointer = nullptr; delete pointer ? Why not use that to make a safe way to delete pointers prematurely if required, where they would normally be deleted some other time and cause an error with a normal delete? It is not the same, because while you may be setting the pointer to null, the contents that the pointer pointed to would still be taking up space. Doing

Do we need to synchronize writes if we are synchronizing reads?

瘦欲@ 提交于 2019-12-01 12:53:52
I have few doubts about synchronized blocks. Before my questions I would like to share the answers from another related post Link for Answer to related question . I quote Peter Lawrey from the same answer. synchronized ensures you have a consistent view of the data. This means you will read the latest value and other caches will get the latest value. Caches are smart enough to talk to each other via a special bus (not something required by the JLS, but allowed) This bus means that it doesn't have to touch main memory to get a consistent view. If you only use synchronized, you wouldn't need

Does printf() allocate memory in C?

喜欢而已 提交于 2019-12-01 11:47:32
This simple method just creates an array of dynamic size n and initializes it with values 0 ... n-1. It contains a mistake, malloc() allocates just n instead of sizeof(int) * n bytes: int *make_array(size_t n) { int *result = malloc(n); for (int i = 0; i < n; ++i) { //printf("%d", i); result[i] = i; } return result; } int main() { int *result = make_array(8); for (int i = 0; i < 8; ++i) { printf("%d ", result[i]); } free(result); } When you check the output you will see that it will print some numbers as expected but the last ones are gibberish. However, once I inserted the printf() inside the

JVM heap not released

让人想犯罪 __ 提交于 2019-12-01 09:44:01
I am new to analyzing memory issues in Java. So pardon me if this question seems naive I have application running with following JVM parameters set: -Xms3072m -Xmx3072m -XX:MaxNewSize=1008m -XX:NewSize=1008m -XX:PermSize=224m -XX:MaxPermSize=224m -XX:SurvivorRatio=6 I am using visualVM to monitor the usage : Here is what I see The problem is, even when the application is not receiving any data for processing, the used memory doesn't go down. When the application is started, the used space starts low (around 1GB) but grows as the application is running. and then the used memory never goes down.