heap-memory

Setting variable to NULL after free

旧街凉风 提交于 2019-11-26 01:51:01
问题 In my company there is a coding rule that says, after freeing any memory, reset the variable to NULL. For example ... void some_func () { int *nPtr; nPtr = malloc (100); free (nPtr); nPtr = NULL; return; } I feel that, in cases like the code shown above, setting to NULL does not have any meaning. Or am I missing something? If there is no meaning in such cases, I am going to take it up with the \"quality team\" to remove this coding rule. Please advice. 回答1: Setting unused pointers to NULL is

java.lang.OutOfMemoryError: GC overhead limit exceeded

扶醉桌前 提交于 2019-11-26 01:34:46
问题 I am getting this error in a program that creates several (hundreds of thousands) HashMap objects with a few (15-20) text entries each. These Strings have all to be collected (without breaking up into smaller amounts) before being submitted to a database. According to Sun, the error happens \"if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown.\".

java.lang.OutOfMemoryError: Java heap space

﹥>﹥吖頭↗ 提交于 2019-11-26 00:13:20
问题 I am getting the following error on execution of a multi-threading program java.lang.OutOfMemoryError: Java heap space The above error occured in one of the threads. Upto my knowledge, Heap space is occupied by instance variables only. If this is correct, then why this error occurred after running fine for sometime as space for instance variables are alloted at the time of object creation. Is there any way to increase the heap space? What changes should I made to my program so that It will

How is the default Java heap size determined?

北战南征 提交于 2019-11-25 23:15:54
问题 If I omit the -Xmxn option from the Java command line then a default value will be used. According to Java documentation \"the default value is chosen at runtime based on system configuration\" What system configuration settings influence the default value? 回答1: On Windows, you can use the following command to find out the defaults on the system where your applications runs. java -XX:+PrintFlagsFinal -version | findstr HeapSize Look for the options MaxHeapSize (for -Xmx ) and InitialHeapSize

Detect application heap size in Android

大憨熊 提交于 2019-11-25 23:15:35
问题 How do you programmatically detect the application heap size available to an Android app? I heard there\'s a function that does this in later versions of the SDK. In any case, I\'m looking for solution that works for 1.5 and upwards. 回答1: There are two ways to think about your phrase "application heap size available": How much heap can my app use before a hard error is triggered? And How much heap should my app use, given the constraints of the Android OS version and hardware of the user's

Increase heap size in Java

匆匆过客 提交于 2019-11-25 22:16:18
问题 I am working on a Windows 2003 server (64-bit) with 8 GB RAM. How can I increase the heap memory maximum? I am using the -Xmx1500m flag to increase the heap size to 1500 Mb. Can I increase the heap memory to 75% of physical memory (6 GB Heap)? 回答1: You can increase to 4GB on a 32 bit system. If you're on a 64 bit system you can go higher. No need to worry if you've chosen incorrectly, if you ask for 5g on a 32 bit system java will complain about an invalid value and quit. As others have

How to deal with “java.lang.OutOfMemoryError: Java heap space” error?

和自甴很熟 提交于 2019-11-25 22:15:22
问题 I am writing a client-side Swing application (graphical font designer) on Java 5 . Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found Ergonomics in the 5.0 Java Virtual Machine and others saying on Windows machine the JVM defaults max heap size as 64MB . Given this situation, how

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

半城伤御伤魂 提交于 2019-11-25 21:40:41
问题 I get this error message as I execute my JUnit tests: java.lang.OutOfMemoryError: GC overhead limit exceeded I know what an OutOfMemoryError is, but what does GC overhead limit mean? How can I solve this? 回答1: This message means that for some reason the garbage collector is taking an excessive amount of time (by default 98% of all CPU time of the process) and recovers very little memory in each run (by default 2% of the heap). This effectively means that your program stops doing any progress

Java 7 (JDK 7) garbage collection and documentation on G1

梦想的初衷 提交于 2019-11-25 20:44:34
Java 7 has been out for a while now, but I cannot find any good resources on the configuration of the garbage collectors , specifically the new G1 collector . My questions: Is G1 the default collector in Java 7 and if not how do I activate G1? What optional settings does g1 have in Java7? Were there any changes made to other collectors like cms or the parallel collector in Java 7? Where can I find good documentation on garbage collection in Java 7? The G1 garbage collector is not the default in my installation of Java, version 1.7.0_01. You can see for yourself by using with some extra command