memory-management

QT4 Memory Management

I come from a fairly strong C background, and have a rather solid foundation in C++. More recently I've been working with C# and other higher level languages. A project I'm looking at working on could really benefit from using QT4, but I have some questions on memory management I can't seem to understand. I've read the QT4 documentation ...

_heapwalk reports _HEAPBADNODE, causes breakpoint or loops endlessly

I use _heapwalk to gather statistics about the Process' standard heap. Under certain circumstances i observe unexpected behaviours like: _HEAPBADNODE is returned some breakpoint is triggered inside _heapwalk, telling me the heap might got corrupted access violation inside _heapWalk. I saw different behaviours on different Computers....

How to increment an NSDate...

I'm trying to implement a method that will increment an NSDate instance variable by one month. I'm having memory management problems with this. (I'm using MallocScribble and NSZombieEnabled, and getting the message: -[CFDate copy]: message sent to deallocated instance 0x3d9dfa0) My question comes down to: what's the best way to incremen...

Any useful suggestions to figure out where memory is being free'd in a Win32 process?

An application I am working with is exhibiting the following behaviour: During a particular high-memory operation, the memory usage of the process under Task Manager (Mem Usage stat) reaches a peak of approximately 2.5GB (Note: A registry key has been set to allow this, as usually there is a maximum of 2GB for a process under 32-bit Wi...

Static methods and instance methods in memory

How are those different Method types handled in memory. I found two different explanations to this: Static methods are only once in memory, whereas instance methods are in memory multiple times, one for each instance to handle the references to membervariables correctly in each instance. All methods are only once in memory and instanc...

Should i override operators new/delete in my c++ WIn32 applications

Hi, I know Microsoft themselves used to recommend overriding operator new with calls to HeapCreate() and HeapAlloc(), but that was a while ago. See KB139638 for more details. Would i still benefit from overriding new/delete on Win32? What would be the recommended implementation? TIA. ...

UINavigationController: When Does a Pushed View Receive the Dealloc Message?

I would expect that after I push a view controller I then need to release my ownership of the view controller like I did below. CustomViewController *nextViewController = [[CustomViewController alloc] initWithNibName:@"CustomView" bundle:nil]; [[self navigationController] pushViewController:nextViewController animated:YES]; [nextViewCo...

When you exit a C application, is the malloc-ed memory automatically freed?

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 program, ie after allocating some space in memory, will that memory I allocated be still allocated (ie basically taking up space) after I exi...

Objective-C: object init and memory management

Given the next code snippet: ... - (void) setTotalAmount: (NSNumber*)input { [totalAmount autorelease]; totalAmount = [input retain]; } - (void) dealloc { [totalAmount release]; [super dealloc]; } ... What I want to understand how really we set value. We allocate local (instance) var and "retain" to input var. But w...

gdb gives an error, but program runs fine

I have a simple C program which has a pointer to a character array. To initiate it, I use malloc, and resize then set it x number of times later on in the program. When I resize it once with realloc, gdb doesn't show any errors, however, if I try calling the resize function again, gdb shows the following error: warning: Invalid Address...

C tutorial question relating to calloc vs malloc

I am following this tutorial (http://theocacao.com/document.page/234). I am confused about this paragraph, mainly the lines relating to calloc: We can also use a variation of the malloc function, called calloc. The calloc function takes two arguments, a value count and the base value size. It also clears the memory before returning a...

How can you find the processor number a thread is running on?

I have a memory heap manager which partitions the heap into different segments based on the number of processors on the system. Memory can only be allocated on the partition that goes with the currently running thread's processor. This will help allow different processors to continue running even if two different ones want to allocate ...

OpenGL GPU Memory cleanup, required?

I have a simple but unanswered question. Do I have to clean up all DisplayLists, Textures, (Geometry-)Shaders and so on by hand via the glDelete* functions, or does the GPU mem get freed automagically when my Program exits/crashes? Note: GPU mem refers to dedicated memory on a dedicated Graphics card, not CPU memory. ...

Can't seem to be able to re alloc a released UIView. iPhone Programming

I have a UIView which I create programmatically roughly like so: @implementation SlideShowView - (id)initWithImages { … if (self=[super initWithFrame:CGRectMake(0, 0, 320, 480)]) { // init objects here } return self; } - (void)dealloc { printf("dealloc slide show view\n"); [[NSNotificationCenter defau...

nesting "alloc" with a setter in Objective-C

Hi, first question here, this is regarding the iPhoneOS3 not MacOSX. I am fairly new to Objective-C and I've never developed in a environment without automatic garbage collection so I am a little confused by this. Here's some valid code assigning a view controller to an app delegate from an example off Apple.com: MyViewController *aView...

BSS, Stack, Heap, Data, Code/Text - Where each of these start in memory?

Segments of memory - BSS, Stack, Heap, Data, Code/Text (Are there any more?). Say I have a 128MB RAM, Can someone tell me: How much memory is allocated for each of these memory segments? Where do they start? Please specify the address range or something like that for better clarity. What factors influence which should start where? ...

How to know if the the value of an array is composed by zeros?

Hey, if you can get a more descriptive tittle please edit it. I'm writing a little algorithm that involves checking values in a matrix. Let's say: char matrix[100][100]; char *ptr = &matrix[0][0]; imagine i populate the matrix with a couple of values (5 or 6) of 1, like: matrix[20][35]=1; matrix[67][34]=1; How can I know if the bi...

NSButton state != 0 when alloc'd

I have two projects that include the same code: NSButton *button = [[NSButton alloc] initWithFrame:ctrlRect]; (gdb) print (int)[button state] $1 = 1 in the other project $1 = 0 I am compiling both with GCC 4.2, 10.6 - no other apparent differences in compiler settings. If I alloc/init an NSButton earlier in the app, state = 0 wh...

In C++, is it possible to reconcile stack-based memory management and polymorphism?

I love declaring variables on the stack, especially when using the standard container. Each time you avoir a new, you avoid a potential memory leak. I also like using polymorphism, ie class hierarchies with virtual functions. However, it seems these features are a bit incompatible: you can't do: std::vector<BaseType> vec; vec.push_back...

Memory Management for shared array elements

I am a little confused about releasing memory for array elements that are shared by multiple arrays. Here's the scenario: Manager class has an instance variable NSMutableArray* mgrArray Helper class has an instance variable NSMutableArray* helperArray. Manager's init method: NSMutableArray* mgrArray = [[[NSMutableArray alloc] init]...