Click here to Skip to main content
15,881,281 members
Everything / Memory

Memory

memory

Great Reads

by Dmitriy Gakh
Development in C# without care of resource consumption can lead to overloading the system. This article describes a case with large waste of memory and CPU time and how to avoid it.
by Gamil Yassin
Types of Artificial Neural Networks
by PFalkowski
The way of calculating amount of memory occupied by some object in C#.NET
by honey the codewitch
Some C++ magic to help cut down on heap abuse for simple scenarios

Latest Articles

by Ayush Vijaywargi
Enhancing Android app stability by integrating LeakCanary with RxJava for efficient memory leak detection and resolution.
by ToughDev
How to use NFS to transfer files between Windows and MS-DOS 6.22
by ToughDev
Retro68 GCC-based SDK for 68K Mac
by ToughDev
Fix high Windows memory usage caused by large metafile

All Articles

Sort by Score

Memory 

28 Aug 2015 by Dmitriy Gakh
Development in C# without care of resource consumption can lead to overloading the system. This article describes a case with large waste of memory and CPU time and how to avoid it.
17 Dec 2012 by Espen Harlinn
I and some good friends of mine decided to try making a smaller game in C++ just for fun Great :-Da lot of people worries about memory fragmentation Many spend time worrying on things that eventually turn out not to be a problem ... Is this something you should worry aboutProbably...
17 Feb 2015 by PFalkowski
The way of calculating amount of memory occupied by some object in C#.NET
13 Jun 2012 by Aescleal
You're doing pointer manipulation on pointers to dynamically allocated memory. This has a couple of effects: - you're orphaning blocks of memory - you couldn't free R1, even if you wanted to - as Albert said you're overrunning an array somewhere. You're not assigning xa anywhere for one...
20 Jun 2012 by Sergey Alexandrovich Kryukov
A static collection is a typical source of a "memory leak by design". In .NET, you are more or less protected from the casual memory leaks, because you don't have to clean up memory after every operation you use it; the Garbage Collector (GB) takes care about it. Despite of the common believe,...
20 Jun 2012 by DaveyM69
What sort of data are you storing in your list? I have used (in testing) extremely large lists without issue.The size of any item in .NET is limited to 2GB. The maximum value for a lists capacity is 2147483647 so theoretically you could store that many bytes in the list and be right on the...
2 Mar 2016 by Dave Kreskowiak
Next time, just put the code in the post, not in an image.No, you're wrong about the "8 bytes".The top code snippet in the image is just a shortcut, an "auto-implemented" property. Behind the scenes it's doing exactly the same thing as the second code snippet in the image.In both...
14 Dec 2020 by honey the codewitch
Some C++ magic to help cut down on heap abuse for simple scenarios
12 Mar 2024 by Ayush Vijaywargi
Enhancing Android app stability by integrating LeakCanary with RxJava for efficient memory leak detection and resolution.
19 Jan 2013 by OriginalGriff
With C++ (and C before it) all variables are stack based, unless they are directly allocated from the heap with a malloc (old style) or new (preferable) - in which case you must use the appropriate delete or free method when you are finished with it.There is no such thing as "dynamic"...
7 Feb 2013 by OriginalGriff
Because it is good practice.Which means it's a good idea to get into the habit of freeing everything you allocate. If you do it every time, making sure that when you allocate something, you automatically set up the code to de-allocate it, then it becomes second nature and you don't foget when...
16 Aug 2013 by pasztorpisti
This is basically a NULL pointer exception. Its 0x10 and not zero because you are using the NULL pointer as a pointer to a struct/class and you are trying to access a member of that struct/class that is on offset 0x10 inside the struct/class. Still it is a NULL pointer "exception".The bug is...
11 Oct 2013 by ASP.NET Community
CachingAuthor: Prakash Singh MehraIntroduction: It is a way to store the frequently used data into the server memory which can be retrieved very
31 May 2012 by Aescleal
The quickest way to avoid memory leaks is to not make them in the first place. There's really no reason to manually manage memory any more, it's a bit of a mug's game.That said there are a few of things you can try without digging into the standard library source code (nv3 knows more than I...
19 Aug 2012 by Sergey Alexandrovich Kryukov
CLI is a managed platform. It means that you don't directly allocate, but, more importantly, you do not control reclaiming memory. In terms of C#, you always allocate managed heap memory with "new" operators and never need to clean up the memory. It is done through the mechanism of Garbage...
19 Sep 2012 by mohammad sami aak
how i can display memory type?in vb.netwindows applecationeg:memory type : ddr3memory Capacity (size): 3072 MB** Attach a picture of your program is readyHis name is: CPU-Zhttp://im23.gulfup.com/2012-09-19/1348086800251.jpg[^]
19 Sep 2012 by fjdiewornncalwe
I found something about this here[^]. I can't confirm the validity of this information, but at least it is something. The answer that has the information is this:According to this kb article[^], certain types of memory will be listed as unknown since it wasn't in the SMBIOS (which WMI...
7 Feb 2013 by Matthew Faithfull
In this particular case there's no compelling reason to care but it's an extremely good habit to get into to free everything you allocate, using RAII where ever appropriate because 99.99% of the time not doing so will be an uncontrolled memory leak, a potential security risk, massive noise in...
7 Apr 2013 by Matthew Faithfull
What you say may be completely correct but I believe the problem goes deeper than one of cache coherency. The issue I think is rather to do with the language specification and the current state of the art in optimising compilers.The C++ language specification does not, contrary to common...
7 Apr 2013 by H.Brydon
The professor was correct.The short answer to your question is that the code sequence illustrated needs to turn the operations into atomic operations which, amongst other things, will flush the cache and disable/workaround the instruction reordering as described.
25 Sep 2013 by Sergey Alexandrovich Kryukov
Of course you cannot do such things in such a simple way. Even if you managed to copy the executable segment memory correctly. This is not how the memory is filled in when PE file is loaded. It's done via the system loader which actually makes a lot of work.The PE describes some chunks of...
28 Feb 2014 by Dave Kreskowiak
The first thing I'd do is make sure there's nothing running on the customer machine that is consuming memory or large numbers of handles, reducing these resources for your application. I ran into a problem with a Dell service that was running and it was leaking handles badly it eventually made...
31 Mar 2014 by OriginalGriff
"why is that?"Because you converted it wrong.Probably, because you don't know C++ that well, and aren't used to pointers.Don't try an convert C++ to C# unless you are pretty much familiar with both languages: they may look very similar, but they are very, very different animals which...
23 May 2014 by OriginalGriff
Yes. It does - that is what I would expect.Think about it: What datatype is your memory buffer? It's a uint32_t (because MEMORY_BUFFER is declares as a pointer to uint32_t) which means it addresses 32 bit quantities, so when you add 1 to the pointer it moves it to the next uint32_t values, not...
20 Jun 2014 by Raul Iloc
1.Basically you should use sizeof() and/or Marshal.SizeOf() to calculate it.2.The size of the right, left and parent properties, becuase they are reference to other Node objects should be 4 (for Win32 application) and 8 (for Win64 application).3.You could use memory profiler tools to...
26 Jul 2014 by PIEBALDconsult
"the exe file has to be compiled by compiler to Assembly code"No."Compiler is a tool to open exe file"No.The closest to that is that, when using a DLL, the compiler needs to access the publicly available symbols of the DLL. But that's at compile time, not at run time.I...
26 Jul 2014 by Sergey Alexandrovich Kryukov
First of all, let me congratulate you with having a "nice trouble". No doubt, having an ugly trouble would be much worse.Let me continue with Solution 1."…when an *.exe is loaded, the OS will check the DLL file of program".No. The statement makes no sense, because there is no...
12 Apr 2015 by Frankie-C
Hard stressing will always remain a relative definition, because in spite of all your efforts there will be a condition for failure that was not touched in the test ;-)Apart from Murphy's law, if there is something in particular that you want test it's better to concentrate on it instead.you...
17 May 2015 by Frankie-C
From what you say it seems that you have some confusion about how a modern OS manage memory.First of all I suggest you to read this[^] and this[^] to clarify the basics (in an actual OS the memory is virtual and each executable generally is allocated on the same standard virtual address...
3 Apr 2016 by Jochen Arndt
Have a look at How to Troubleshoot Out of Memory Issues (System.OutOfMemoryException) in ASP.NET[^].
29 Jun 2017 by Lockwood
Something like this? IO.FileStream fs = new IO.FileStream(myFile, IO.FileMode.Open, IO.FileAccess.Read); IO.MemoryStream ms = new IO.MemoryStream(); fs.CopyTo(ms);
25 Sep 2017 by Dave Kreskowiak
If you're looking at Task Manager to determine the amount of memory your app is using, DON'T! It's lying to you. What you see in Task Manager is how much memory is RESERVED for your app's execution, NOT how much it's actually using. The .NET CLR manages the execution of your application and...
20 Feb 2018 by Mike Diack
Try Inside CRT: Debug Heap Management[^] But from my own notes also: This is a list of some of the know magic numbers used by Microsoft which can be useful to know when debugging an application. 0xABABABAB Guard Bytes used by HeapAlloc() or LocalAlloc to mark "no man’s land" after allocated...
23 May 2018 by Jochen Arndt
If you declare an object on the stack as in your case, it is destroyed automatically when going out of scope. As already noted at your other question, you should pass it by reference to avoid creating a copy. So it should be: { const std::vector arr = {1, 2, 3}; doSomething(arr);...
30 Nov 2018 by mrsilver
A fixed memory pool class written in C++ for generic usage
14 Dec 2018 by Richard MacCutchan
// shmat to attach to shared memory char *str2 = (char*) shmat(shmid2,(void*)0,0); printf("Data written in message2: %s\n",str2); You create str2 to point to an area of shared memory. However, you never write anything to that area so it contains whatever was last written...
20 Aug 2019 by OriginalGriff
Memory isn't released back to the OS when it's done with in your code unless the OS specifically asks for it - which it only does when it starts to run low. If you use a lump of memory, the memory manager checks it's free list, and if it needs extra it requests it from the OS. That remains part...
29 Jan 2020 by phil.o
The concept you need to do your task is called External sorting[^].
29 Jan 2020 by OriginalGriff
The first thing to do is to start by looking at what you have to sort: what does the file contain that needs sorting? What does it need sorting by? Think about it: if you have a stack of mixed banknotes on your desk, there are many ways to sort them: by denomination, by colour, by size, by...
12 Mar 2020 by Stefan_Lang
1. You can only delete objects that you created on the heap. Visualizza is an array declared on the stack, so you may not delete it. Trying to do so will always result in a crash. 2. You have allocated arrays of strings in your functions...
25 Aug 2020 by Jon McKee
malloc allocates a block of uninitialized, contiguous memory of the requested size in bytes and passes back a void* pointer since it has no idea what you want that memory for. So, how do we calculate how many bytes we need then? Well, in this...
25 Aug 2020 by Rick York
Jon is right on the nose. Your for loop should be rewritten to look something like this : struct Food { char* name; int weight; int calories; }; struct Food lunches[ LUNCH_QTY ]; struct Food * pfood; char...
3 Jan 2021 by Stefan_Lang
This is a C function although you can choose to use it C++ too. The result must be cast to the desired result type, e. g.: char * my_10_characters = (char*)malloc(10); P.S.: I've mentioned that this is a C function, because in C++ you should...
3 Jan 2021 by Richard MacCutchan
To add to what Stefan said. The returned pointer is declared void because malloc has no way of knowing what you plan to store i the memory space. The caller uses a cast to let the compiler know what types are going to be used by the rest of the...
3 Jan 2021 by Rick York
You are right that a function return a void is not returning anything. However, this function returns a type of (void *). I wrapped it in parenthesis so you can see it as a singular type. In the Windows SDK they have wrapped it in a type...
18 Jun 2021 by OriginalGriff
Under normal circumstances, no. If the leak became extreme so that all available non-virtual memory was used, then paging could drive up CPU usage taking care of it, but you wouldn't notice that because the disk thrashing would be orders of...
23 Jan 2023 by Rick York
Segment faults are caused by attempting to address an invalid address. I will assume data is a pointer to the base of an image buffer. What you can do is check the validity of the rest of that expression. That means you can write a function...
17 Feb 2023 by OriginalGriff
You allocate a block of memory (20 chars worth) and tell the system that that is a set of pointers to chars - because Str is a pointer to a pointer to a char. Which is effectively a pointer to a string. Think of Str as a array of pointers to...
17 Mar 2023 by Dev Leader
This article is follow up content to previous articles I've written about iterators and collections, but the benchmark results were NOT what I expected!
16 Apr 2012 by OriginalGriff
There are a couple of possibilities, the major ones are1) Your recursive routine is being called too deep.2) Your routine is not releasing memory when it is finished with it.3) Your routine is allocating more memory than you think.4) Your heap size is set too small.The first three...
17 May 2012 by Aescleal
If all you're doing is reading a file, comparing it to some other version of it and then overwriting the differences why not just blat the correct one over the incorrect one after you've done the comparison?Your code seems well complicated for what you're trying to do. If you simplify your...
23 May 2012 by Sergey Chepurin
For this answer i have compiled the information from different sources but mainly from Q&A of Stackoverflow.com.A process has 5 different areas of memory allocated1. Code - text segment2. Initialized data – .data segment3. Uninitialized data – .bss segment4. Heap5. Stack...
23 May 2012 by Ahmed_Mostafa_Mahmoud
Thanks for your efforts.i had solved the problem by adding this code in the top of each .cpp file, and that leaded me to the correct position on the memory leak:#ifdef _DEBUG#define new DEBUG_NEW#endifThanks,
31 May 2012 by Pablo Aliskevicius
The way I used, when confronted with a leak, was all manual - no tools.The important thing is: you don't have to find the leak in order to fix it. Look for malloc() calls (and friends: calloc, realloc, strdup): replace as many of them as possible by stack variables, and all the others by...
3 Nov 2012 by OriginalGriff
Um. I'm not surprised.Your code is effectivelyint j = 2;for (int i = 0; i
8 Nov 2012 by TorstenH.
Memory Management on doc.Blackberry.com[^]Here you should be able to retrieve the wanted info:net.rim.device.api.system.Memory[^]
9 Dec 2012 by Sergey Alexandrovich Kryukov
There is no such thing as "force" to run something to "run on a single process". Processes are totally under your control. If you don't create a process, it is not created by anything by itself. And using GC is not recommended.Your "without going too much into assemblies and stuff like that"...
12 Feb 2013 by Matej Hlatky
According to many posts on Internet, this is not possible, since VB.NET does not support unsafe code.You can use your unsafe C# code within different assembly and reference it in your VB.NET project.
19 May 2013 by Abhinav S
You can use this via WMI - http://www.blackwasp.co.uk/GetMemory.aspx[^].
23 Jun 2013 by Sergey Alexandrovich Kryukov
Who told you that the position in file streams are 32-bit? Usually, uint64 type is used for that. Of course, you cannot always map the whole file onto physical memory, but you don't really need it, even in 64-bit instruction-set architectures which also use uint64 pointers in flat memory...
6 Jul 2013 by Sergey Alexandrovich Kryukov
First big design mistake I can see is: remove all I/O from all class members, otherwise, what are you creating, a class which can only work with cin and cout, nothing else?[EDIT]As to your question: ptr1 does not have to be assigned to the same address, as it is assigned to a freshly...
12 Jul 2013 by Sergey Alexandrovich Kryukov
There is nothing much to discuss here. "Out of memory" should be prevented, not fixed. If you have not enough memory, you have not enough. Your 7 MB is next to nothing these days though. Anyway, you did not provide any relevant information, not a sample project. Maybe your system memory is...
19 Jul 2013 by ThatsAlok
IPC using memory mapped file in managed VC++
16 Sep 2013 by OriginalGriff
Basically you can't, without some fairly advanced use of Reflection to recursively parse your type and get the sizes of each of it's constituent parts - which may well have their own contained classes, which may... you get the idea.And it'll be sloooow.There is apparently another way....
24 Oct 2013 by Trapper-Hell
Not the best way to do it, but since no one else provided any suggestions, here's what I did:1. The LoaderApp loads all the referenced assemblies in memory (as shown in the code snippet of the original question2. The loaded Assemblies are passed to a private method implemented in the...
19 Dec 2013 by Dave Kreskowiak
Do NOT look in Task Manager to see how much memory your app is using. It's lying to you! Use PerfMon and the .NET Memory counters instead.Task Manager is showing you how much memory the .NET CLR is RESERVED for your app, not how much it's actually using.
22 Dec 2013 by Sergey Alexandrovich Kryukov
You don't have a proven fact that your memory is leaking. See Solution 1. However, it does not mean that you cannot have memory leak, managed, unmanaged or both. You need to understand how memory clean up is done, in case of managed and unmanaged memory, as well as other resources. Please see my...
22 Jan 2014 by Trey Wheeler
Using Java 1.6 on Android API 13 (3.2):We are working on a View Model framework. In this framework we can wait on another property to have a value before executing. In the following example we are awaiting the value from ModuleViewProperty before attempting to fetch a data count....
14 Feb 2014 by AdityaBohra
Hi, I am working on a project in which I have to read the size on 'Memory Dumps' and also remove these. I tried to get the path from registries but it giving error of "File not found" , in this thing I need your help. Is there any method to detect 'Memory Dumps' and remove those 'Memory...
12 Mar 2014 by Raul Iloc
1.The Viewstate is a cache saved into the Web Page itself, is used mainly to preserve data between page postbacks and will be automatically lost when you redirect to other page.2.The Session is a cache associated with each user that access a web application, so it exist at the user level for...
13 Mar 2014 by JoCodes
Good comments provided by Raul. Just wanted to reiterate that avoid Session being used for storing Dataset which contains large number of Rows. Always remember that, Session is User specific, and if we store large data it stores and holds it separately for each User consuming the Server...
31 Mar 2014 by Terence Wallace
using System;// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS// and compile with -DPSAPI_VERSION=1private void PrintMemoryInfo(uint processID){ System.IntPtr hProcess; PROCESS_MEMORY_COUNTERS pmc = new PROCESS_MEMORY_COUNTERS(); // Print the process...
10 May 2014 by OriginalGriff
Start with the debugger: put a breakpoint on the ShowDialog line and run you app. when it reaches the line, the debugger will stop and wait for you. Look closely at the OpenFileDialog and make sure everything looks reasonable. Then look at the preceding lines of code and see if there is anything...
23 May 2014 by sid2x
Hi,Say I've allocated some memory using malloc(), the operating system will give me the address to the memory allocated (i.e. a page). Now I am trying to browse this area of memory as if it was a 16-bit address space which starts from 0 and ends at 0xFFFF. (Don't ask why!, Just wanted to...
5 Dec 2020 by Member 10563121
I have a problem that has stumped me involving memory mapping, and interchange between C++ (Visual Studio 2012 under Win7 32bit) and Python 2.7. In my C++ code I have a large (2Mbyte) image that updates at about 25Hz. I share this with another C++ .exe happily, using non-persistent (only...
27 Aug 2014 by 2006 Flauzer
I have noticed using the ProcXP (VMMap) that some ASP.NET applications (.NET 4)load (or maps?) some assemblies twice or more.I use VS 2010 (W7 x64), with the AnyCPU option and tested in 2008 R2 x64 server....the apps are both complied with release/debug options, the result it's the...
27 Aug 2014 by 2006 Flauzer
i think that this solves the question:https://connect.microsoft.com/VisualStudio/feedback/details/780964/assemblies-loaded-twice-in-64bit-application[^]
1 Dec 2014 by OriginalGriff
What the heck are you doing that for?You appear to be reallocating the stack space each time you pop an item off it - and presumably whenever you add something to it as well.That really is spectacularly inefficient: you would get considerably better performance even if you implemented your...
3 Dec 2014 by AndersonChau
Memory management(MM) may appear in every part of the computer system.At the lowest level, Computer platforms have special hardware for segmentation, paging and memory protection. Compiler may divide the binary image into code/data/zero initialized data section. The OS/VM may...
9 Dec 2014 by Dave Kreskowiak
OK, everyone is focused on the Pen. That's not the problem in the code you posted.Well, there is one small problem where you're not disposing the Pen before your app terminates. This will lead to a handle leak and eventually break Window but you have to run this app over and over again,...
24 Dec 2014 by Philippe Mori
The first question is do you really have to have such continuous big array. Why not using 200 array of 1 MB for example?200M is a big array for 32 bit application on computer that does not have much RAM etc.As far as I know large allocation are forwarded to the system and thus does not...
29 Dec 2014 by Shaun Blain
I would suggest that if you are using the code from the article you referenced that the issue is in there. I browsed through the source code and there are several items that I would clean up. The first two being the binary reader and writer. These should be specifically disposed when the class...
7 Feb 2015 by Sergey Alexandrovich Kryukov
No! Your example uses value object (as opposed ) which does not have to be collected. More exactly, it could be a stack variable, then it will be removed when the stack frame is removed (say, on method return), and this has nothing to do with allocation or deallocation, or this could be an...
20 Mar 2015 by Afzaal Ahmad Zeeshan
You can do nothing to improve this. I am also using Android Studio, and it uses RAM similarly. That is why I don't prefer Google's software; Picasa, Chrome etc. They all are not memory efficient software. I prefer Microsoft's Visual Studio[^] or Eclipse[^] or NetBeans[^] IDE. They're all better...
30 Sep 2015 by Dave Kreskowiak
Start -> Run -> PerfMonEverything you could possibly want to capture and more.
3 Oct 2015 by Jochen Arndt
The errors are in the lines 546, 547, 548, 584, and 586 of SharedMemory.cpp where you are using the variable mxArray_tag. The type of that variable seems to be defined in line 83 of the include file SharedMemory.hpp.See the MSDN error description for the errors (press F1 when the error...
14 Jan 2016 by Wendelius
Based on the error stack I would check that you actually close the window at some point and the thread being called ends working. Based on the code you have provided, you show a new window on each thread call and from the stack you can see the the stack overflow happens exactly there, when the...
2 Mar 2016 by Dave Kreskowiak
Your going about it wrong. You open the process as if it was a file and start reading from the beginning of the process, an example of which you can find at Minesweeper, Behind the scenes[^].
30 Apr 2016 by Dave Kreskowiak
You'd be better off asking this in a forum dedicated to the hardware you're using.But, I don't know of a single micro that will let you use Flash as RAM.You either need to get hardware that has more memory in it (your best option!) and/or find a compiler that generates better/smaller...
11 May 2016 by Dmitriy Gakh
I would like to propose my vision that may differ from purpose of your code. But it could introduce some new points that could help to find the best solution.My vision is that process is an OS part. So the one question is how much memory OS allocated for the process. OS calls or external...
15 Sep 2016 by discompsys
This tutorial describes how to convert the recursive method call in said algorithm into a flat loop call, to save memory in restricted environments.
24 Aug 2017 by Dave Kreskowiak
All this is doing is returning a pointer to memory address 1234, which in Windows will probably get you a security exception if you try to read what's there from your code.
26 Aug 2017 by Salman Amintabar
Hi I'm change the gradle properties file and it's work for me ;-) Open 'gradle.properties' file in editor and change it like this: Original: org.gradle.jvmargs=-Xmx1536m Change to: org.gradle.jvmargs=-Xms512m -Xmx1024m The 'Xms' is minimum and 'Xmx' is maximum memory of the gradle can use...
23 May 2018 by User 13204940
Hi, Just a quick memory management question, let's say I have the following: const std::vector intArray = {1, 2, 3}; delete intArray; This should allocate memory for the array then free it up again. How does this work in this situation? doSomething({1, 2, 3}); void doSomething(const...
23 May 2018 by Leo Chapiro
Have you tried to compile this code: const std::vector intArray = {1, 2, 3}; delete intArray; I think no, because you should get an error on "delete intArray" like "Expression must be a pointer". You can only delete the objects created on the heap with "new", not such stack objects...
15 Dec 2018 by Rick York
I use shared memory a LOT and for all kinds of different things. The one thing you can't do with it is save pointers because a pointer in one process' address space is not valid to another process. However, you can save and use offsets between processes. Anyway, I usually "map" a data...
26 Feb 2019 by Gerry Schmitz
You should check the result from HeapFree() and LastError() if you want to get a better idea of what's going on. You're also "closing the file" (that accesses the heap) AFTER freeing the heap when you shouldn't be "touching" the heap anymore. HeapFree function | Microsoft Docs[^]
26 Feb 2019 by steveb
Memory allocated by HeapAlloc is not movable. Since the memory is not movable, it is possible for the heap to become fragmented. You need to get the largest file size out of 100 files and allocate memory only once. You will then reuse it for all 100 files and deallocate it once
18 Apr 2019 by MetalKid007
I'm pretty late to this, but I have a real solution and can explain why! It turns out that LocalReport here is using .NET Remoting to dynamically create a sub appdomain and run the report in order to avoid a leak internally somewhere. We then notice that, eventually, the report will release all...