Questions tagged [memory]
Use this tag for memory management or issues in programming. For questions about memory hardware issues or errors in general software, go to https://superuser.com, or https://serverfault.com if this is related to enterprise-level hardware or software.
                                	
	memory
    
                            
                        
                    
            36,239
            questions
        
        
            3733
            votes
        
        
            61
            answers
        
        
            750k
            views
        
    How can I create a memory leak in Java?
                I just had an interview where I was asked to create a memory leak with Java.
Needless to say, I felt pretty dumb, having no idea how to start creating one.
What would an example be?
            
        
       
    
            1046
            votes
        
        
            17
            answers
        
        
            1.1m
            views
        
    How do I determine the size of an object in Python?
                How do I get the size occupied in memory by an object in Python?
            
        
       
    
            904
            votes
        
        
            32
            answers
        
        
            1.5m
            views
        
    How can I measure the actual memory usage of an application or process?
                How do you measure the memory usage of an application or process in Linux?
From the blog article of Understanding memory usage on Linux, ps is not an accurate tool to use for this intent.
Why ps is &...
            
        
       
    
            882
            votes
        
        
            10
            answers
        
        
            215k
            views
        
    What is a "cache-friendly" code?
                What is the difference between "cache unfriendly code" and the "cache friendly" code?
How can I make sure I write cache-efficient code?
            
        
       
    
            836
            votes
        
        
            10
            answers
        
        
            345k
            views
        
    How do I discover memory usage of my application in Android?
                How can I find the memory used on my Android application, programmatically?
I hope there is a way to do it. Plus, how do I get the free memory of the phone too?
            
        
       
    
            786
            votes
        
        
            36
            answers
        
        
            2.1m
            views
        
    Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted
                I have a bunch of client point of sale (POS) systems that periodically send new sales data to one centralized database, which stores the data into one big database for report generation.
The client ...
            
        
       
    
            763
            votes
        
        
            10
            answers
        
        
            444k
            views
        
    How to determine CPU and memory consumption from inside a process
                I once had the task of determining the following performance parameters from inside a running application:
Total virtual memory available
Virtual memory currently used
Virtual memory currently used ...
            
        
       
    
            731
            votes
        
        
            32
            answers
        
        
            685k
            views
        
    Docker error : no space left on device
                I installed docker on a Debian 7 machine in the following way 
$ echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
$ sudo apt-get update
$ curl -sSL https://...
            
        
       
    
            686
            votes
        
        
            29
            answers
        
        
            370k
            views
        
    How to determine the size of an object in Java
                I have an application that reads a CSV file with piles of data rows. I give the user a summary of the number of rows based on types of data, but I want to make sure that I don't read in too many rows ...
            
        
       
    
            619
            votes
        
        
            10
            answers
        
        
            847k
            views
        
    How can I explicitly free memory in Python?
                I wrote a Python program that acts on a large input file to create a few million objects representing triangles.  The algorithm is:
read an input file
process the file and create a list of triangles, ...
            
        
       
    
            548
            votes
        
        
            24
            answers
        
        
            140k
            views
        
    Which is faster: Stack allocation or Heap allocation
                This question may sound fairly elementary, but this is a debate I had with another developer I work with.
I was taking care to stack allocate things where I could, instead of heap allocating them. He ...
            
        
       
    
            443
            votes
        
        
            22
            answers
        
        
            434k
            views
        
    How to get the size of a JavaScript object?
                I want to know the size occupied by a JavaScript object.
Take the following function:
function Marks(){
  this.maxMarks = 100;
}
function Student(){
  this.firstName = "firstName";
  this.lastName =...
            
        
       
    
            440
            votes
        
        
            6
            answers
        
        
            131k
            views
        
    If a DOM Element is removed, are its listeners also removed from memory?
                If a DOM Element is removed, are its listeners removed from memory too?
            
        
       
    
            370
            votes
        
        
            3
            answers
        
        
            57k
            views
        
    What is the purpose of std::launder?
                P0137 introduces the function template  std::launder and makes many, many changes to the standard in the sections concerning unions, lifetime, and pointers.
What is the problem this paper is solving? ...
            
        
       
    
            365
            votes
        
        
            10
            answers
        
        
            462k
            views
        
    How do I profile memory usage in Python?
                I've recently become interested in algorithms and have begun exploring them by writing a naive implementation and then optimizing it in various ways.
I'm already familiar with the standard Python ...
            
        
       
    
            341
            votes
        
        
            9
            answers
        
        
            261k
            views
        
    What does .view() do in PyTorch?
                What does .view() do to a tensor x? What do negative values mean?
x = x.view(-1, 16 * 5 * 5)
            
        
       
    
            319
            votes
        
        
            16
            answers
        
        
            530k
            views
        
    How do I read a large csv file with pandas?
                I am trying to read a large csv file (aprox. 6 GB) in pandas and i am getting a memory error:
MemoryError                               Traceback (most recent call last)
<ipython-input-58-...
            
        
       
    
            317
            votes
        
        
            19
            answers
        
        
            141k
            views
        
    "register" keyword in C?
                What does the register keyword do in C language?  I have read that it is used for optimizing but is not clearly defined in any standard.  Is it still relevant and if so, when would you use it?
            
        
       
    
            308
            votes
        
        
            7
            answers
        
        
            436k
            views
        
    How do I determine the correct "max-old-space-size" for Node.js?
                I'm having some trouble to understand how Node.js acts based on the parameter max-old-space-size.
In my case, for example, I'm running two t2.small AWS instances (2GB of RAM).
Not sure why, but I did ...
            
        
       
    
            301
            votes
        
        
            8
            answers
        
        
            291k
            views
        
    Virtual Memory Usage from Java under Linux, too much memory used
                I have a problem with a Java application running under Linux.
When I launch the application, using the default maximum heap size (64 MB), I see using the tops application that 240 MB of virtual ...
            
        
       
    
            284
            votes
        
        
            20
            answers
        
        
            410k
            views
        
    How to find out which processes are using swap space in Linux?
                Under Linux, how do I find out which process is using the swap space more?
            
        
       
    
            280
            votes
        
        
            8
            answers
        
        
            121k
            views
        
    Purpose of memory alignment
                Admittedly I don't get it. Say you have a memory with a memory word of length of 1 byte. Why can't you access a 4 byte long variable in a single memory access on an unaligned address(i.e. not ...
            
        
       
    
            268
            votes
        
        
            12
            answers
        
        
            125k
            views
        
    What is memory fragmentation?
                I've heard the term "memory fragmentation" used a few times in the context of C++ dynamic memory allocation.  I've found some questions about how to deal with memory fragmentation, but can't find a ...
            
        
       
    
            265
            votes
        
        
            3
            answers
        
        
            54k
            views
        
    How much of ‘What Every Programmer Should Know About Memory’ is still valid?
                I am wondering how much of Ulrich Drepper's What Every Programmer Should Know About Memory from 2007 is still valid. Also I could not find a newer version than 1.0 or an errata.
(Also in PDF form on ...
            
        
       
    
            261
            votes
        
        
            4
            answers
        
        
            228k
            views
        
    How is the java memory pool divided?
                I’m currently monitoring a Java application with jconsole. The memory tab lets you choose between:
Heap Memory Usage
Non-Heap Memory Usage
Memory Pool “Eden Space”
Memory Pool “Survivor Space”
Memory ...
            
        
       
    
            256
            votes
        
        
            12
            answers
        
        
            551k
            views
        
    How to see top processes sorted by actual memory usage?
                I have a server with 12G of memory. A fragment of top is shown below:
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                ...
            
        
       
    
            256
            votes
        
        
            17
            answers
        
        
            154k
            views
        
    Is the sizeof(some pointer) always equal to four?
                For example:
sizeof(char*) returns 4.  As does int*, long long*, everything that I've tried.  Are there any exceptions to this?
            
        
       
    
            255
            votes
        
        
            6
            answers
        
        
            384k
            views
        
    How to get object size in memory? [duplicate]
                I need to know how much bytes my object consumes in memory (in C#). for example how much my Hashtable, or SortedList, or List<String>.
            
        
       
    
            246
            votes
        
        
            12
            answers
        
        
            150k
            views
        
    What is the memory consumption of an object in Java?
                Is the memory space consumed by one object with 100 attributes the same as that of 100 objects, with one attribute each?
How much memory is allocated for an object?
How much additional space is used ...
            
        
       
    
            244
            votes
        
        
            17
            answers
        
        
            261k
            views
        
    Get OS-level system information
                I'm currently building a Java app that could end up being run on many different platforms, but primarily variants of Solaris, Linux and Windows.
Has anyone been able to successfully extract ...
            
        
       
    
            241
            votes
        
        
            12
            answers
        
        
            59k
            views
        
    How dangerous is it to access an array out of bounds?
                How dangerous is accessing an array outside of its bounds (in C)? It can sometimes happen that I read from outside the array (I now understand I then access memory used by some other parts of my ...
            
        
       
    
            231
            votes
        
        
            18
            answers
        
        
            924k
            views
        
    How can I find Java heap size and memory used (Linux)?
                How can I check heap size (and used memory) of a Java application on Linux through the command line?
I have tried through jmap. But it gives information about internal memory areas, like Eden, PermGen,...
            
        
       
    
            229
            votes
        
        
            5
            answers
        
        
            130k
            views
        
    How do cache lines work?
                I understand that the processor brings data into the cache via cache lines, which - for instance, on my Atom processor - brings in about 64 bytes at a time, whatever the size of the actual data being ...
            
        
       
    
            229
            votes
        
        
            8
            answers
        
        
            6k
            views
        
    What are the dangers when creating a thread with a stack size of 50x the default?
                I'm currently working on a very performance critical program and one path I decided to explore that may help reduce resource consumption was increasing my worker threads' stack size so I can move most ...
            
        
       
    
            220
            votes
        
        
            8
            answers
        
        
            145k
            views
        
    What does .contiguous() do in PyTorch?
                What does x.contiguous() do for a tensor x?
            
        
       
    
            220
            votes
        
        
            9
            answers
        
        
            320k
            views
        
    Where in memory are my variables stored in C?
                By considering that the memory is divided into four segments: data, heap, stack, and code, where do global variables, static variables, constant data types, local variables (defined and declared in ...
            
        
       
    
            218
            votes
        
        
            6
            answers
        
        
            97k
            views
        
    How are multi-dimensional arrays formatted in memory?
                In C, I know I can dynamically allocate a two-dimensional array on the heap using the following code:
int** someNumbers = malloc(arrayRows*sizeof(int*));
for (i = 0; i < arrayRows; i++) {
    ...
            
        
       
    
            217
            votes
        
        
            5
            answers
        
        
            105k
            views
        
    Approximate cost to access various caches and main memory?
                Can anyone give me the approximate time (in nanoseconds) to access L1, L2 and L3 caches, as well as main memory on Intel i7 processors?
While this isn't specifically a programming question, knowing ...
            
        
       
    
            215
            votes
        
        
            2
            answers
        
        
            96k
            views
        
    Redis cache vs. using memory directly
                I have not used Redis yet, but I have heard about it and plan to try using it for caching data.
I have heard that Redis uses memory as a cache store database. What's the point of Redis, since I can ...
            
        
       
    
            206
            votes
        
        
            5
            answers
        
        
            97k
            views
        
    Java using much more memory than heap size (or size correctly Docker memory limit)
                For my application, the memory used by the Java process is much more than the heap size.
The system where the containers are running starts to have memory problem because the container is taking much ...
            
        
       
    
            206
            votes
        
        
            12
            answers
        
        
            327k
            views
        
    How do I monitor the computer's CPU, memory, and disk usage in Java?
                I would like to monitor the following system information in Java:
Current CPU usage** (percent)
Available memory* (free/total)
Available disk space (free/total)
*Note that I mean overall memory ...
            
        
       
    
            203
            votes
        
        
            14
            answers
        
        
            256k
            views
        
    What is the difference between buffer and cache memory in Linux?
                To me it's not clear what's the difference between the two Linux memory concepts : buffer and cache. I've read through this post and it seems to me  that the difference between them is the expiration ...
            
        
       
    
            195
            votes
        
        
            8
            answers
        
        
            104k
            views
        
    Determining memory usage of objects?
                I'd like to work out how much RAM is being used by each of my objects inside my current workspace. Is there an easy way to do this?
            
        
       
    
            194
            votes
        
        
            15
            answers
        
        
            56k
            views
        
    What does "Memory allocated at compile time" really mean?
                In programming languages like C and C++, people often refer to static and dynamic memory allocation. I understand the concept but the phrase "All memory was allocated (reserved) during compile time" ...
            
        
       
    
            193
            votes
        
        
            9
            answers
        
        
            10k
            views
        
    Why does appending "" to a String save memory?
                I used a variable with a lot of data in it, say String data.
I wanted to use a small part of this string in the following way:
this.smallpart = data.substring(12,18);
After some hours of debugging (...
            
        
       
    
            191
            votes
        
        
            8
            answers
        
        
            105k
            views
        
    String literals: Where do they go?
                I am interested in where string literals get allocated/stored.
I did find one intriguing answer here, saying:
  Defining a string inline actually embeds the data in the program itself and cannot be ...
            
        
       
    
            190
            votes
        
        
            8
            answers
        
        
            410k
            views
        
    How to clear variables in ipython?
                Sometimes I rerun a script within the same ipython session and I get bad surprises when variables haven't been cleared. How do I clear all variables?
And is it possible to force this somehow every ...
            
        
       
    
            190
            votes
        
        
            4
            answers
        
        
            28k
            views
        
    What happens when a computer program runs?
                I know the general theory but I can't fit in the details.
I know that a program resides in the secondary memory of a computer. Once the program begins execution it is entirely copied to the RAM. Then ...
            
        
       
    
            189
            votes
        
        
            6
            answers
        
        
            138k
            views
        
    Difference between "on-heap" and "off-heap"
                Ehcache talks about on-heap and off-heap memory. What is the difference? What JVM args are used to configure them?
            
        
       
    
            189
            votes
        
        
            5
            answers
        
        
            222k
            views
        
    How to monitor the memory usage of Node.js?
                How can I monitor the memory usage of Node.js?