heap-memory

Jersey service file upload causes OutOfMemoryError

折月煮酒 提交于 2019-11-29 01:31:18
I'm developing form submission service with Jersey 2.0. The form includes several text fields and one file field. I need to extract file , file name , file media type and file content type and save them in object store. @Path("upload") @Consumes({MediaType.MULTIPART_FORM_DATA}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public class UploadService { @POST public BlobDo uploadFile(FormDataMultiPart uploadedBody) { String accountSid = uploadedBody.getField("account-sid").getValue(); String apiToken = uploadedBody.getField("api-token").getValue(); String checksum =

Get the size (in bytes) of an object on the heap

戏子无情 提交于 2019-11-28 20:51:01
I'm aware you can use MemoryLayout<T>.size to get the size of a type T . For example: MemoryLayout<Int32>.size // 4 However, for class instances (objects), MemoryLayout<T>.size returns the size of the reference to the object (8 bytes on 64 bit machines), not the size of the actual objects on the heap. class ClassA { // Objects should be at least 8 bytes let x: Int64 = 0 } class ClassB {// Objects should be at least 16 bytes let x: Int64 = 0 let y: Int64 = 0 } MemoryLayout<ClassA>.size // 8 MemoryLayout<ClassB>.size // 8, as well :( How can I get the size of the objects themselves? For those

How to create a struct on the stack in C?

℡╲_俬逩灬. 提交于 2019-11-28 20:47:06
问题 I understand how to create a struct on the heap using malloc . Was looking for some documentation regarding creating a struct in C on the stack but all docs. seem to talk about struct creation on heap only. 回答1: The same way you declare any variable on the stack: struct my_struct {...}; int main(int argc, char **argv) { struct my_struct my_variable; // Declare struct on stack . . . } 回答2: To declare a struct on the stack simply declare it as a normal / non-pointer value typedef struct { int

Java out of heap space during serialization

烈酒焚心 提交于 2019-11-28 20:29:49
The following code is causing a OutOfMemmoryError: heap space for some 3 million rows. Memory allocated to JVM is 4 GB, using 64 bit installation. while (rs.next()) { ArrayList<String> arrayList = new ArrayList<String>(); for (int i = 1; i <= columnCount; i++) { arrayList.add(rs.getString(i)); } objOS.writeObject(arrayList); } The memory referenced by the ArrayList is eligible for garbage collection in each iteration of the while loop, and internally JVM calls garbage collection ( System.gc() ) before throwing an OutOfMemory Error because of heap space. So why is the exception occurring? Is

Why do -Xmx and Runtime.maxMemory not agree

此生再无相见时 提交于 2019-11-28 19:22:38
When you add -Xmx????m to the command line, the JVM gives you a heap which is close to this value but can be out by up to 14%. The JVM can give you a figure much closer to what you want, but only through trial and error. System.out.println(Runtime.getRuntime().maxMemory()); prints -Xmx1000m -> 932184064 -Xmx1024m -Xmx1g -> 954728448 -Xmx1072m -> 999292928 -Xmx1073m -> 1001390080 I am running HotSpot Java 8 update 5. Clearly, the heap can be something just above 1000000000 but why is this -Xmx1073m instead of say -Xmx1000m ? BTW 1g == 1024m which suggests that 1g should be 1024^3 which is 7%

Where are instance variables of an Object stored in the JVM?

一个人想着一个人 提交于 2019-11-28 18:53:38
Is an instance variable of an object in Java stored on the stack or method area of the JVM? Also, do we have different instance variable for multiple threads? If it is stored in method area how is instance variable different from static variable storage? Matej Špilár Stack and heap are the memories allocated by the OS to the JVM that runs in the system. Stack is a memory place where the methods and the local variables are stored. (variable references either primitive or object references are also stored in the stack). Heap is a memory place where the objects and its instance variable are

C: How to free nodes in the linked list?

戏子无情 提交于 2019-11-28 18:45:28
How will I free the nodes allocated in another function? struct node { int data; struct node* next; }; struct node* buildList() { struct node* head = NULL; struct node* second = NULL; struct node* third = NULL; head = malloc(sizeof(struct node)); second = malloc(sizeof(struct node)); third = malloc(sizeof(struct node)); head->data = 1; head->next = second; second->data = 2; second->next = third; third->data = 3; third->next = NULL; return head; } I call the buildList function in the main() int main() { struct node* h = buildList(); printf("The second element is %d\n", h->next->data); return 0;

Why application is dying randomly?

Deadly 提交于 2019-11-28 18:41:33
I am developing an music player app. All works fine except the app dies suddenly. Sometimes this happens when the app starts, and sometimes after running for long time. Sometimes all goes well without app getting died. I observed the log to get to know what is the causing the app to die and found this: 11-02 16:39:39.293: A/libc(3556): @@@ ABORTING: INVALID HEAP ADDRESS IN dlfree 11-02 16:39:39.293: A/libc(3556): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1) The full log is given below, what I found in logcat when the app died: 11-02 16:39:39.293: A/libc(3556): @@@ ABORTING: INVALID HEAP

Can't change tomcat 7 heap size

淺唱寂寞╮ 提交于 2019-11-28 17:58:32
I have set the heap size of tomcat 7 by adding the following line in catalina.sh export CATALINA_OPTS="-Xms512m -Xmx1024m" then stopped and started the tomcat. but when tried to get the heap size using the command jmap -heap , i can notice that the memory doesn't change: Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 526385152 (502.0MB) NewSize = 1048576 (1.0MB) MaxNewSize = 4294901760 (4095.9375MB) OldSize = 4194304 (4.0MB) NewRatio = 2 SurvivorRatio = 8 PermSize = 16777216 (16.0MB) MaxPermSize = 67108864 (64.0MB) Heap Usage: PS Young Generation Eden Space:

LocalAlloc Vs GlobalAlloc Vs malloc Vs new

ぃ、小莉子 提交于 2019-11-28 17:28:35
问题 I have searched for this on various links, but still the doubt persist. I do not understand the difference between LocalAlloc vs GlobalAlloc vs malloc vs new for memory allocation. I have gone through this link of MSDN: Comparing Memory Allocation Methods Please explain the following statement: The malloc function has the disadvantage of being run-time dependent. The new operator has the disadvantage of being compiler dependent and language dependent 回答1: Excerpts from Raymond Chen's