memory-management

Delphi - structures' strings not being freed [FastMM manager]

﹥>﹥吖頭↗ 提交于 2020-03-01 06:41:52
问题 If I declare PSomeStruct = ^TSomeStruct; TSomeStruct = record s1 : string; end; and I run the following code: var p: PSomeStruct; begin new(p); p^.s1:= 'something bla bla bla'; dispose(p); the FastMM 4 memory manager reports that there was a memory leak (type: string, data dump: "something bla bla bla"). However, if I do set the s1 string to empty before calling dispose it's OK. The second way I found is to change from record type to class, then instead of new I'm creating the instance, and

node --max_old_space_size is not working

◇◆丶佛笑我妖孽 提交于 2020-03-01 06:40:07
问题 Node Version: 6.9.x My application was giving me FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error. So I tried changing the memory allocation using max_old_space_size flag While executing my server.js, I am giving the --max_old_space_size=4096 argument. However, it keeps crashing with same error as before. Also, I noticed the numbers in the error thrown while crashing. Looks like its still the default allocation of 1.4 GB. Here's my error message: <---

Can still print a string after I freed it?

半世苍凉 提交于 2020-02-27 23:20:39
问题 I am learning and testing memory allocation in C and I want to test what happens if free() is called. I expected there could be a segmentation fault or pointer is NULL after I run the program below. However, I can still successfully print the string as in Output. I also tried to free str twice, then an error as Output 2 occurred. It seems the previously allocated memory is successfully deallocated, but the data on the memory is not cleaned up. Is that correct? If that is the case, when will

new [], delete [] complexity

余生长醉 提交于 2020-02-26 09:09:09
问题 I already know that the new[] operator first allocates memory and then calls the constructor for each element and that the delete[] operator first calls the destructor for each element and then frees memory and, because of that, they both have an O(n) time complexity. But if I have a class, for which I have not defined any constructor/destructor, will the complexity still be O(n), or will it be just O(1)? For instance, if I have two classes: class foo { public: int a; foo() { a = 0; // more

How does realloc() reallocate the memory?

风流意气都作罢 提交于 2020-02-23 00:37:56
问题 How does realloc() reallocate the memory which was first allocated by malloc() ? I know that you need to use malloc() before you´re able to reallocate the memory, but I don´t understand how that really should work. What if a dynamic-memory object gets decreased in size by realloc() ? Is this respective piece of the object just erased after the call to realloc() ? My Question is: How does the realloc() function reallocate a dynamic-memory object created by malloc() ? Note: I did this Q&A

Memory Allocation for Variable Declared in Class

拈花ヽ惹草 提交于 2020-02-18 05:05:29
问题 As Value type variable allocates memory in Stack where as Reference Type allocates it in Heap. So how the memory allocated when a value type variable(eg int i =4;) is declared in the reference type (eg. in a class). How the overall memory allocation works in .net for value type & reference typ, and also value type inside the scope of refence type. Please explain it or provide any links regarding that. Thanks 回答1: So how the memory allocated when a value type variable(eg int i =4;) is declared

Memory Allocation for Variable Declared in Class

ぃ、小莉子 提交于 2020-02-18 05:05:26
问题 As Value type variable allocates memory in Stack where as Reference Type allocates it in Heap. So how the memory allocated when a value type variable(eg int i =4;) is declared in the reference type (eg. in a class). How the overall memory allocation works in .net for value type & reference typ, and also value type inside the scope of refence type. Please explain it or provide any links regarding that. Thanks 回答1: So how the memory allocated when a value type variable(eg int i =4;) is declared

Memory Allocation for Variable Declared in Class

痴心易碎 提交于 2020-02-18 05:05:21
问题 As Value type variable allocates memory in Stack where as Reference Type allocates it in Heap. So how the memory allocated when a value type variable(eg int i =4;) is declared in the reference type (eg. in a class). How the overall memory allocation works in .net for value type & reference typ, and also value type inside the scope of refence type. Please explain it or provide any links regarding that. Thanks 回答1: So how the memory allocated when a value type variable(eg int i =4;) is declared

Why don't purely functional languages use reference counting?

北战南征 提交于 2020-02-17 07:01:33
问题 In purely functional languages, data is immutable. With reference counting, creating a reference cycle requires changing already created data. It seems like purely functional languages could use reference counting without worrying about the possibility of cycles. Am is right? If so, why don't they? I understand that reference counting is slower than GC in many cases, but at least it reduces pause times. It would be nice to have the option to use reference counting in cases where pause times

Why don't purely functional languages use reference counting?

百般思念 提交于 2020-02-17 06:56:55
问题 In purely functional languages, data is immutable. With reference counting, creating a reference cycle requires changing already created data. It seems like purely functional languages could use reference counting without worrying about the possibility of cycles. Am is right? If so, why don't they? I understand that reference counting is slower than GC in many cases, but at least it reduces pause times. It would be nice to have the option to use reference counting in cases where pause times