memory-management

Setting Objects to Null/Nothing after use in .NET

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 Idisposable interface to release some resources. Although the object can still be something after it is disposed (hence the isDisposed property ...

WebSphere 6.1 generational gc default nursery size limit

By default the nursery is supposed to be 25% of the heap, we have the initial heap size set to 1GB. With verbose gc on, we see that our nursery is sized at 55-60MB. We have forced the size using -Xmns256M -Xmnx512M. Shouldn't this happen automatically? ...

How to log mallocs

This is a bit hypothetical and grossly simplified but... Assume a program that will be calling functions written by third parties. These parties can be assumed to be non-hostile but can't be assumed to be "competent". Each function will take some arguments, have side effects and return a value. They have no state while they are not runn...

Common memory optimization

What are the most common memory optimizations in csharp, dotnet 2.0. Wanted to see if there common things that people may not be doing by default in winform app ...

Is Global Memory Initialized in C++

And if so, how? (Second) Clarification: When a program starts up, what is in the memory space which will become global memory, prior to primitives being initialized. I'm trying to understand if it is zeroed out, or garbage for example. The situation is can a singleton reference be set - via an instance() call, prior to its initializa...

How does the NSAutoreleasePool autorelease pool work?

As I understand it, anything created with an alloc, new, or copy needs to be manually released. For example: int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } My question, though, is wouldn't this be just as valid?: int main(void) { NSAutoreleasePool *poo...

deleting a buffer through a different type of pointer?

Say I have the following C++: char *p = new char[cb]; SOME_STRUCT *pSS = (SOME_STRUCT *)p; delete pSS; Is this safe according to the C++ standard? Do I need to cast back to a char* and then use delete[]? I know it'll work in most C++ compilers, because it's plain-ordinary-data, with no destructors. Is it guaranteed to be safe? ...

Will this C++ code cause a memory leak (casting array new)

I have been working on some legacy C++ code that uses variable length structures (TAPI), where the structure size will depend on variable length strings. The structures are allocated by casting array new thus: STRUCT* pStruct = (STRUCT*)new BYTE [sizeof(STRUCT) + nPaddingSize]; Later on however the memory is freed using a delete call:...

Does Scripting.Dictionary's RemoveAll() method release all of its elements first?

In a VB6 application, I have a Dictionary whose keys are Strings and values are instances of a custom class. If I call RemoveAll() on the Dictionary, will it first free the custom objects? Or do I explicitly need to do this myself? Dim d as Scripting.Dictionary d("a") = New clsCustom d("b") = New clsCustom ' Are these two lines nece...

Memory management in C++

What are some general tips to make sure I don't leak memory in C++ programs ? How do I figure out who should free memory that has been dynamically allocated ? ...

What and where are the stack and heap

Programming language books usually explain that value types are created on the stack, and reference types created on the heap, without really explaining what these two things are. With my only programming experience being in high level languages, I haven't read a clear explanation of this. I mean I understand what a stack is, but where...

Does the Java VM move objects in memory, and if so - how?

Does the Java virtual machine ever move objects in memory, and if so, how does it handle updating references to the moved object? I ask because I'm exploring an idea of storing objects in a distributed fashion (ie. across multiple servers), but I need the ability to move objects between servers for efficiency reasons. Objects need to b...

How can I report to users what is consuming the process address space of a windows application while they're running it?

I'm writing the memory manager for an application, as part of a team of twenty-odd coders. We're running out of memory quota and we need to be able to see what's going on, since we only appear to be using about 700Mb. I need to be able to report where it's all going - fragmentation etc. Any ideas? ...

How is the Page File available calculated in Windows Task Manager?

In Vista Task Manager, I understand the available page file is listed like this: Page File inUse M / available M In XP it's listed as the Commit Charge Limit. I had thought that: Available Virtual Memory = Physical Memory Total + Sum of Page Files But on my machine I've got Physical Memory = 2038M, Page Files = 4096M, Page File Av...

Smart Pointers: Or who owns you baby?

C++ is all about memory ownership Aka "Ownership Semantics" It is the responsibility of the owner of a chunk of dynamically allocated memory to release that memory. So the question really becomes who owns the memory. In C++ ownership is documented by the type a RAW pointer is wrapped inside thus in a good (IMO) C++ program it is very r...

Tools to view/solve Windows XP memory fragmentation

We have a java program that requires a large amount of heap space - we start it with (among other command line arguments) the argument -Xmx1500m, which specifies a maximum heap space of 1500 MB. When starting this program on a Windows XP box that has been freshly rebooted, it will start and run without issues. But if the program has run ...

Memory Management in Objective-C

I come from a C/C++ background and the dynamic nature of ObjectiveC is somewhat foreign to me, is there a good resource anyone can point me to for some basic memory management techniques in ObjectiveC? ex. retaining, releasing, autoreleasing For instance, is it completely illegal to use a pointer to an Objective C object and treat it as...

How to simulate memory allocation errors

My C application uses 3rd libraries, which do their own memory management. In order to be robust, my application has code to deal with failures of library functions due to lack of free memory. I would like to test this code, and for this, I need to simulate failures due to lack of memory. What tool/s are recommended for this? My enviro...

Python memory profiler

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 Memory Validator. And open source ones are PySizer and Heapy. I haven't tried anyone, so I wanted to know which one is the best considering...

Resources that have to be manually cleaned up in C#?

What resources have to be manually cleaned up in C#? ...and what are the consquences of not doing so? For example, say i have the following code: myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); //Use Brush If i don't clean up the brush using the dispose method, i'm assuming the garbage collector frees the memory ...