Skip to main content
Filter by
Sorted by
Tagged with
1173 votes
21 answers
310k views

I have the following code. #include <iostream> int * foo() { int a = 5; return &a; } int main() { int* p = foo(); std::cout << *p; *p = 8; std::cout << *...
9565 votes
30 answers
2.0m views

What are the stack and heap? Where are they located physically in a computer's memory? To what extent are they controlled by the OS or language run-time? What is their scope? What determines their ...
mattshane's user avatar
  • 95.7k
1002 votes
19 answers
188k views

I stumbled upon Stack Overflow question Memory leak with std::string when using std::list<std::string>, and one of the comments says this: Stop using new so much. I can't see any reason you ...
bitgarden's user avatar
  • 10.7k
155 votes
8 answers
42k views

I know that the compiler will sometimes initialize memory with certain patterns such as 0xCD and 0xDD. What I want to know is when and why this happens. When Is this specific to the compiler used? ...
LeopardSkinPillBoxHat's user avatar
527 votes
26 answers
258k views

Has anyone here ever used C++'s "placement new"? If so, what for? It looks to me like it would only be useful on memory-mapped hardware.
Head Geek's user avatar
  • 40.1k
197 votes
9 answers
694k views

I am running into issues trying to use large objects in R. For example: > memory.limit(4000) > a = matrix(NA, 1500000, 60) > a = matrix(NA, 2500000, 60) > a = matrix(NA, 3500000, 60) ...
Benjamin's user avatar
  • 12k
1514 votes
5 answers
3.1m views

What are the Xms and Xmx parameters in JVMs - and what are their default values?
Pankaj's user avatar
  • 15.6k
1093 votes
17 answers
1.2m views

How do I get the size occupied in memory by an object in Python?
user46646's user avatar
  • 160k
113 votes
11 answers
26k views

I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it. Thanks.
Moszi's user avatar
  • 3,236
840 votes
10 answers
356k views

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?
Andrea Baccega's user avatar
640 votes
10 answers
920k views

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, ...
Nathan Fellman's user avatar
626 votes
20 answers
395k views

I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc you should call free and when you use the new operator you should pair with delete and it is a ...
user avatar
777 votes
8 answers
388k views

I want to know the memory usage of my Python application and specifically want to know what code blocks/portions or objects are consuming most memory. Google search shows a commercial one is Python ...
Anurag Uniyal's user avatar
336 votes
13 answers
224k views

I want to know how malloc and free work. int main() { unsigned char *p = (unsigned char*)malloc(4*sizeof(unsigned char)); memset(p,0,4); strcpy((char*)p,"abcdabcd"); // **deliberately ...
Priyanka Mishra's user avatar
362 votes
24 answers
898k views

This error message is being presented, any suggestions? Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php
panidarapu's user avatar
  • 9,141
308 votes
15 answers
223k views

What is the difference between new/delete and malloc/free? Related (duplicate?): In what cases do I use malloc vs new?
MrDatabase's user avatar
  • 44.7k
550 votes
28 answers
144k views

What tricks do people use to manage the available memory of an interactive R session? I use the functions below [based on postings by Petr Pikal and David Hinds to the r-help list in 2004] to list (...
Dirk is no longer here's user avatar
293 votes
10 answers
144k views

Is it allowed to delete this; if the delete-statement is the last statement that will be executed on that instance of the class? Of course I'm sure that the object represented by the this-pointer is ...
Martijn Courteaux's user avatar
233 votes
7 answers
204k views

What is the difference between delete and delete[] operators in C++?
shreyasva's user avatar
  • 13.7k
46 votes
6 answers
13k views

IP_ADAPTER_INFO *ptr=new IP_ADAPTER_INFO[100]; if I free using delete ptr; will it lead to memory leak, if not then why ? This is disassembly code generated by VS2005 ; delete ptr; 0041351D mov ...
Satbir's user avatar
  • 6,542
473 votes
12 answers
501k views

Is there a way for a Python program to determine how much memory it's currently using? I've seen discussions about memory usage for a single object, but what I need is total memory usage for the ...
rwallace's user avatar
  • 34.1k
397 votes
14 answers
476k views

I'm a bit confused with JavaScript's delete operator. Take the following piece of code: var obj = { helloText: "Hello World!" }; var foo = obj; delete obj; After this piece of code has been ...
Steve Harrison's user avatar
181 votes
4 answers
230k views

I have a few related questions regarding memory usage in the following example. If I run in the interpreter, foo = ['bar' for _ in xrange(10000000)] the real memory used on my machine goes up to 80....
Jared's user avatar
  • 26.5k
225 votes
5 answers
233k views

I am pre-allocating some memory to my a vector data member. Example: class A { vector<string> t_Names; public: A () : t_Names(1000) {} }; At some point in time, if the t_Names.size()...
iammilind's user avatar
  • 70.5k
76 votes
6 answers
46k views

When the garbage collector runs and releases memory does this memory go back to the OS or is it being kept as part of the process. I was under the strong impression that the memory is never actually ...
Jim's user avatar
  • 19.7k
170 votes
7 answers
346k views

I would like to increase (or decrease) the amount of memory available to R. What are the methods for achieving this?
medriscoll's user avatar
  • 27.6k
73 votes
2 answers
28k views

I have an iOS app written in Swift that is leaking memory - in certain situation some objects should be released but they are not. I have learnt about the issue by simply adding deinit debug messages ...
Rasto's user avatar
  • 18k
365 votes
8 answers
226k views

Is it safe to delete a NULL pointer? And is it a good coding style?
qiuxiafei's user avatar
  • 6,047
282 votes
6 answers
84k views

A simple test app: cout << new int[0] << endl; outputs: 0x876c0b8 So it looks like it works. What does the standard say about this? Is it always legal to "allocate" empty block of memory?...
user avatar
594 votes
4 answers
401k views

I am trying to use the perfmon windows utility to debug memory leaks in a process. This is how perfmon explains the terms: Working Set is the current size, in bytes, of the Working Set of this ...
pankajt's user avatar
  • 7,904
66 votes
7 answers
18k views

In JavaScript, we have two ways of making a "class" and giving it public functions. Method 1: function MyClass() { var privateInstanceVariable = 'foo'; this.myFunc = function() { alert(...
MgSam's user avatar
  • 12.9k
116 votes
3 answers
62k views

On page 17 of this WWDC14 presentation, it says Working with Objective-C? Still have to manage autorelease pools autoreleasepool { /* code */ } What does that mean? Does it mean that if my code ...
Ethan's user avatar
  • 18.9k
72 votes
16 answers
50k views

I've allocated an "array" of mystruct of size n like this: if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) { /* handle error */ } Later on, I only have access to p, and no longer have n. Is ...
Joel's user avatar
  • 12k
119 votes
7 answers
330k views

I would like to know what is the difference between static memory allocation and dynamic memory allocation? Could you explain this with any example?
Nishant Kumar's user avatar
225 votes
9 answers
336k views

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 ...
starkk92's user avatar
  • 5,974
470 votes
17 answers
233k views

I just finished a test as part of a job interview, and one question stumped me, even using Google for reference. I'd like to see what the StackOverflow crew can do with it: The memset_16aligned ...
JimDaniel's user avatar
  • 12.8k
72 votes
7 answers
167k views

I have a class that contains a dynamically allocated array, say class A { int* myArray; A() { myArray = 0; } A(int size) { myArray = new int[size]; } ~...
Domenic's user avatar
  • 113k
71 votes
7 answers
9k views

5.3.4 [expr.new] of the C++11 Feb draft gives the example: new(2,f) T[5] results in a call of operator new[](sizeof(T)*5+y,2,f). Here, x and y are non-negative unspecified values representing array ...
Mooing Duck's user avatar
  • 67.6k
197 votes
16 answers
120k views

Should you set all the objects to null (Nothing in VB.NET) once you have finished with them? I understand that in .NET it is essential to dispose of any instances of objects that implement the ...
John's user avatar
  • 30.7k
115 votes
9 answers
48k views

Let's say I have the following C code: int main () { int *p = malloc(10 * sizeof *p); *p = 42; return 0; //Exiting without freeing the allocated memory } When I compile and execute that C ...
Andreas Grech's user avatar
2 votes
1 answer
2k views

I am using BDS 2006 Turbo C++ for a long time now and some of my bigger projects (CAD/CAM,3D gfx engines and Astronomic computations) occasionally throw an exception (for example once in 3-12 months ...
Spektre's user avatar
  • 52.3k
-2 votes
2 answers
1k views

I need to take a file that is inputted by the user and multiply it by another file. That much I know how to do. The problem is one file is an array and the other is a matrix. I need to scan in ...
Jonathan Dina's user avatar
104 votes
4 answers
118k views

There is such code: #include <iostream> int main(){ unsigned int* wsk2 = new unsigned int(5); std::cout << "wsk2: " << wsk2 << " " << *wsk2 << std::endl; ...
scdmb's user avatar
  • 15.7k
17 votes
3 answers
6k views

So I have this program that allocates 256 MB of memory, and after the user presses ENTER it frees the memory and terminates. #include <stdio.h> #include <stdlib.h> int main(void) { ...
Ryan's user avatar
  • 667
137 votes
12 answers
251k views

I have used /proc/meminfo and parsed command response.however it result shows that : MemTotal: 94348 kB MemFree: 5784 kB means. it shows there is only 5MB free memory. Is it ...
Badal's user avatar
  • 4,208
180 votes
9 answers
234k views

Please take a look at the picture below. When we create an object in java with the new keyword, we are getting a memory address from the OS. When we write out.println(objName) we can see a "special" ...
uzay95's user avatar
  • 16.8k
48 votes
5 answers
12k views

Two Python strings with the same characters, a == b, may share memory, id(a) == id(b), or may be in memory twice, id(a) != id(b). Try ab = "ab" print id( ab ), id( "a"+"b" ) Here Python recognizes ...
denis's user avatar
  • 22k
805 votes
2 answers
101k views

Here is the extract from the program in question. The matrix img[][] has the size SIZE×SIZE, and is initialized at: img[j][i] = 2 * j + i Then, you make a matrix res[][], and each field in here is ...
user avatar
211 votes
8 answers
75k views

For the most part with ARC (Automatic Reference Counting), we don't need to think about memory management at all with Objective-C objects. It is not permitted to create NSAutoreleasePools anymore, ...
mk12's user avatar
  • 26.5k
117 votes
20 answers
77k views

Although I do understand the serious implications of playing with this function (or at least that's what I think), I fail to see why it's becoming one of these things that respectable programmers ...

1
2 3 4 5
77