memory-management

Clearing a list

I find it annoying that I can't clear a list. In this example: a = [] a.append(1) a.append(2) a = [] The second time I initialize a to a blank list, it creates a new instance of a list, which is in a different place in memory, so I can't use it to reference the first, not to mention it's inefficient. The only way I can see of retain...

Visual Studio Memory Usage

I find that quite often Visual studio memory usage will average ~150-300 Mb of RAM. As a developer who very often needs to run with multiple instances of Visual studio open. Are there any performance tricks to optimize the ammount of memory that VS uses. I am running VS 2005 with one add-in (TFS) ...

String literals inside functions: automatic variables or allocated in heap?

Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually? I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my program and using it (marked a...

Circular References in Java

Given an aggregation of class instances which refer to each other in a complex, circular, fashion: is it possible that the garbage collector may not be able to free these objects? I vaguely recall this being an issue in the JVM in the past, but I thought this was resolved years ago. yet, some investigation in jhat has revealed a circul...

Ruby Memory Management

I have been using ruby for a while now and I find for bigger projects it can take up a fare amount of memory. What are ruby best practices for reducing memory usage? Please, let each answer have on "best practice" and let the community vote it up ...

In what cases do I use malloc vs new?

I am new to C++ programming but have a solid background in C#, Java and PHP. 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 mistake to mix the two (eg. calling free() on something that...

Largest Heap used in a managed environment? (.net/java)

What is the largest heap you have personally used in a managed environment such as Java or .NET? What were some of the performance issues you ran into, and did you end up getting a diminishing returns the larger the heap was? ...

Dispose of Image in WPF in Listbox (memory leak).

I have a ListBox with a bunch of images in it (done through a datatemplate). The images are created by setting the items source: <Image x:Name="ItemImage" Source="{Binding ImageUrl}"/> and then they are cleared by using the listbox's Items.Clear() method. New Images are added by using the Items.Add method of the listbox. However, ...

Are data members allocated in the same memory space as their objects in C++?

Say I've got a class like this: class Test { int x; SomeClass s; } And I instantiate it like this: Test* t = new Test; Is x on the stack, or the heap? What about s? ...

Why is Erlang crashing on large sequences?

I have just started learning Erlang and am trying out some Project Euler problems to get started. However, I seem to be able to do any operations on large sequences without crashing the erlang shell. Ie.,even this: list:seq(1,64000000). crashes erlang, with the error: eheap_alloc: Cannot allocate 467078560 bytes of memory (of type ...

What is the cost of using autorelease in Cocoa?

Most of Apples documentation seems to avoid using autoreleased objects especially when creating gui views, but I want to know what the cost of using autoreleased objects is? UIScrollView *timeline = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 34)]; [self addSubview:timeline]; [timeline release]; Ultimately should I use ...

How to release the memory that has been used for a variable in C?

How can i release the memory that I used for a variable (e.g. a long string) in C? ...

How can you efficiently check the VM mapping for an address?

I am writing a tracing tool which needs to deal with the output of a a JIT, so the stack can look pretty bizarre at times. I'd like to try to apply some heuristics to addresses to determine if they are code, data or garbage. (If I'm wrong some of the time, it's no big deal; however if the process crashes, not so much.) I can cat /proc...

Is there any way to determine the size of a C++ array programmatically? And if not, why?

This question was inspired by a similar question: How does delete[] “know” the size of the operand array? My question is a little different: Is there any way to determine the size of a C++ array programmatically? And if not, why? Every function I've seen that takes an array also requires an integer parameter to give it the size. But...

Structure Vs Class in C#

When you create an instance of a class with the new operator, memory gets allocated on the heap. When you create an instance of a struct with the new operator where does the memory get allocated, on the heap or on the stack ? ...

Returning Objects in C++

When returning objects from a class, when is the right time to release the memory? Example, class AnimalLister { public: Animal* getNewAnimal() { Animal* animal1 = new Animal(); return animal1; } } If i create an instance of Animal Lister and get Animal reference from it, then where am i supposed to delete it? int ...

Freeing memory allocated to an array of void pointers

I am declaring an array of void pointers. Each of which points to a value of arbitary type. void **values; // Array of void pointers to each value of arbitary type Initializing values as follows: values = (void*)calloc(3,sizeof(void)); //can initialize values as: values = new void* [3]; int ival = 1; float fval = 2.0; ...

JNI memory management using the Invocation API

When I'm building a java object using JNI methods, in order to pass it in as a parameter to a java method I'm invoking using the JNI invocation API, how do I manage its memory? Here's what I am working with: I have a C object that has a destructor method that is more complex that free(). This C object is to be associated with a Java ...

Question about shallow copy in C++

Say I have a struct "s" with an int pointer member variable "i". I allocate memory on the heap for i in the default constructor of s. Later in some other part of the code I pass an instance of s by value to some function. Am I doing a shallow copy here? Assume I didn't implement any copy constructors or assignment operators or anythi...

Determining realloc() behaviour before calling it

As I understand it, when asked to reserve a larger block of memory, the realloc() function will do one of three different things: if free contiguous block exists grow current block else if sufficient memory allocate new memory copy old memory to new free old memory else return null Growing the current block is a v...