memory-management

return large data by reference or as return in function?

拥有回忆 提交于 2020-01-12 04:45:07
问题 On the job today I had a argue with a collage about passing large data between scopes. The myth was that reference uses less memory/CPU usage when passing between 2 scopes. We build a proof of concept who was right... so: function by_return($dummy=null) { $dummy = str_repeat("1",100 * 1024 * 1024); return $dummy; } function by_reference(&$dummy) { $dummy = null; $dummy = str_repeat("1",100 * 1024 * 1024); } echo memory_get_usage()."/".memory_get_peak_usage()."\n"; //1 always returns:

Is it possible to completely avoid heap fragmentation?

不问归期 提交于 2020-01-12 04:37:28
问题 For example, if deallocations of dynamic memory are always done in opposite direction to allocations. In that case, is it guaranteed that heap will not become fragmented? And from theoretical point of view: Does there exist some realistic way for a nontrivial application to manage memory to completely avoid heap fragmentation? (After each atomic change in heap, is heap still unfragmented?) 回答1: Exist some realistical way for nontrivial application how to manage memory to completely avoid heap

Pushing variables to Stack and Variables living in the Stack difference?

China☆狼群 提交于 2020-01-12 04:28:05
问题 So I know that there exists 2 memory areas: Stack and Heap . I also know that if you create a local variable it will live in the Stack, not in the heap. Stack will grow as we push data into it as in: Now I will try to pass the confusion I am having to you: For example this simple Java Code: public class TestClass { public static void main(String[] args) { Object foo = null; Object bar = null; } } is translated into this byte code: public static void main(java.lang.String[]); Code: Stack=1,

How to avoid stack space overflows?

僤鯓⒐⒋嵵緔 提交于 2020-01-12 03:58:17
问题 I've been a bit surprised by GHC throwing stack overflows if I'd need to get value of large list containing memory intensive elements. I did expected GHC has TCO so I'll never meet such situations. To most simplify the case look at the following straightforward implementations of functions returning Fibonacci numbers (taken from HaskellWiki). The goal is to display millionth number. import Data.List # elegant recursive definition fibs = 0 : 1 : zipWith (+) fibs (tail fibs) # a bit tricky

Get visual graph of heap memory usage in Java over a span of time

别说谁变了你拦得住时间么 提交于 2020-01-12 03:28:17
问题 I am currently using Visual VM to monitor the heap memory usage of my Java application. However I would like to somehow see the heap memory usage over a span of time like for example a day and not just get a snapshot.I would like to be able to leave Visual VM or a tool on and let it log the memory usage and then later after one day, I can go back and see a graph of it. Is there a way to do this using Visual VM? If yes, how? If not, what tool can I used to do this? 回答1: Run your Java program

C# not releasing memory after task complete

天大地大妈咪最大 提交于 2020-01-12 02:25:12
问题 The following code is a simplified example of an issue I am seeing. This application consumes approx 4GB of memory before throwing an exception as the dictionary is too big. class Program { static void Main(string[] args) { Program program = new Program(); while(true) { program.Method(); Console.ReadLine(); } } public void Method() { WasteOfMemory memory = new WasteOfMemory(); Task tast = new Task(memory.WasteMemory); tast.Start(); } } public class WasteOfMemory { public void WasteMemory() {

Why ARC is not deallocating memory after popViewController

本秂侑毒 提交于 2020-01-11 17:12:40
问题 I'm pushing and popping ViewControllers in UINavigationController. I'm tracking the memory consumption of my app. While pushing the new viewController the memory consumption is increasing gradually, but when I'm popping the same ViewController using [self.navigationController popViewControllerAnimated:NO]; the memory consumption does not decrease but the constant. That particular viewController can be pushed and popped by user many times which can lead the high memory consumption of app in

increasing memory usage with jquery

你说的曾经没有我的故事 提交于 2020-01-11 13:14:20
问题 I am developing a site which heavily uses jquery (UI) for providing a good user experience. For some (stupid) reason parts of this site are shown within an iframe and there also is a button for refreshing the iframe to get the latest data from the server. The problem is that each time when refreshing the iframe the memory usage increases leading to serious memory problems after some time (Tested in IE8 & 9). But this occurs only if the jquery library is loaded. This behaviour can be seen best

Is pointer arithmetic on allocated storage UB?

前提是你 提交于 2020-01-11 11:35:11
问题 Let's say I want to implement std::vector without invoking any undefined behavior (UB). Is the code below invokes UB: struct X{int i;}; int main(){ auto p = static_cast<X*>(::operator new(sizeof(X)*2)); new(p) X{}; new(p+1) X{};// p+1 UB? } Folowing a selection of quote from the standard that may help: [basic.stc.dynamic.allocation] The pointer returned (by an allocation function) shall be suitably aligned so that it can be converted to a pointer to any suitable complete object type (21.6.2.1

How is Stack memory allocated when using 'push' or 'sub' x86 instructions?

廉价感情. 提交于 2020-01-11 11:09:49
问题 I have been browsing for a while and I am trying to understand how memory is allocated to the stack when doing for example: push rax Or moving the stack pointer to allocate space for local variables of a subroutine: sub rsp, X ;Move stack pointer down by X bytes What I understand is that the stack segment is anonymous in the virtual memory space,i.e., not file backed. What I also understand is that the kernel will not actually map an anonymous virtual memory segment to physical memory until