memory-management

Do I have to autorelease this object?

I am creating an NSDictionary with -initWithObjectsAndKeys:. For every object I provide to that dictionary I call a selfmade method -createFooBarObject, which will create and return the object. Now the problem: The create method by definition should not release the object because it must return it, and the caller is responsible for rel...

Objective-C on GNUstep AutoReleasePool undeclared problem

I'm new to Objective-C and working in GNUstep and MinGW environment. I am compiling this code but having an error: #import "Foundation/Foundation.h" @interface C : NSObject { float f; } - (void) gamerHell: (NSString *) name : (NSString *) lastName ; @end @implementation C - (void) gamerHell: (NSString *) firstName : (NSString *...

Hex dump from memory location

Hi I use a pointer to specify some kind of "shared memory" which I use to exchange data between different processes/threads. Now I would like to have a hex dump of the content of the shared buffer. Does anyone know how to do that? thanks, R ...

Why doesn't free() zero out the memory prior to releasing it?

When we free() memory in C, why is that memory not filled with zero? Is there a good way to ensure this happens as a matter of course when calling free()? I'd rather not risk leaving sensitive data in memory released back to the operating system... ...

Has anyone written or knows of a custom memory manager written in C#?

We have certain application written in C# and we would like it to stay this way. The application manipulates many small and short lived chunks of dynamic memory. It also appears to be sensitive to GC interruptions. We think that one way to reduce GC is to allocate 100K chunks and then allocate memory from them using a custom memory mana...

Fixing memory leaks in Cocoa/ObjC

I'm having a severe memory leak issue with my program. I'm using Apple's Instruments to track my leaks, and in the first few seconds after my app starts there are hundreds and hundreds of leaks listed. The problem is none of them seem to tell me where the leak is coming from. I've gone through all my classes and made sure that anything ...

App crashes without Garbage Collection enabled

As the title says, my app crashes when garbage collection is not enabled. The app pops up for a few seconds and then it just crashes, with nothing but this in the debugger console: [Session started at 2009-08-17 15:03:20 -0600.] GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software F...

Memory managment when drawing to a view on the iPhone

Hey guys, I have a UIImage that I'm instantiating using imageWithData: (the data is loaded from the bundle using [NSData dataWithContentsOfFile:]). I'm then drawing the image like so: NSData *imageData = [NSData dataWithContentsOfFile:fileLocation]; UIImage *myImage = [UIImage imageWithData:imageData]; //These lines are superfluous ...

What might cause half of an NSData object to stay in memory after releasing it?

I'm loading a series of images from a server into NSData objects like so: for (int i = 0; i < 36; i++) { NSURL *url = [NSURL URLWithString:@"http://12.34.56.78/image.jpg"]; NSData *data = [NSData dataWithContentsOfURL:url]; // Further processing here } The problem is that half of each data object is being kept in memory. This d...

simple string runtime error in C?

This code compiles fine but give segmentation fault error while running? Can anyone tell why? #include <stdio.h> #include <string.h> #include <math.h> int main() { const char s2[] = "asdfasdf"; char* s1; strcpy(s1, s2); printf("%s", s1); return 0; } ...

Memory Question

I have some code that results in a EXC_BAD_ACCESS error: recordIDAsString = [ NSString stringWithFormat:@"%i", (int)abRecord.recordID ]; propertyIDAsString = [ NSString stringWithFormat:@"%i", (int)abProperty.propertyID ]; identifierAsString = [ NSString stringWithFormat:@"%i", (int)abProperty.identifier ]; recordIDAsString, proper...

Implementation of multiple interfaces and object instances in .Net

Below is a quick example of what I am doing. Basically, I have multiple interfaces that can be implemented by 1 class or by separate classes, so I store each one in the application. My only question is about the variables myInterface, yourInterface, and ourInterface. Do they reference the same object or are there 3 different objects? ...

Windows 32-bit virtual memory page mapping issue

Hello everyone, I am learning from here about Windows 32-bit virtual memory page mapping, (I am targeting modern Windows versions, like Vista, Win 7, Server 2003/2008 32-bit versions.) http://blogs.msdn.com/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx Two confusions, user space virtual memory ...

how do i make this not leak? (iphone sdk)

I have in effect a string utility that returns a URL. I know that when you do a [[NSString alloc] initWithFormat you have to manaully release the result string. But this case is a bit complicated and I'm not sure how to deal with it. In this code snippet I will be calling the getChartURL method from another class: http://pastie.org/5...

Reading binary files without buffering the whole file into memory in C++

Hi, In order to make a binary comparer I'm trying to read in the binary contents of two files using the CreateFileW function. However, that causes the whole file to be bufferred into memory, and that becomes a problem for large (500MB) files. I've looked around for other functions that'll let me just buffer part of the file instead,...

Objective C Structs and Memory Management

Simple question - do i need to free or release structs. My reason for asking is that I'm use a NSInvocation and the SEL type is a struct. Just want to know if I need to release it. Thanks. ...

How is *array* memory allocated and freed in C and C++?

My question specifically is in regards to arrays, not objects. There a few questions on SO about malloc()/free() versus new/delete, but all of them focus on the differences in how they are used. I understand how they are used, but I don't understand what underlying differences cause the differences in usage. I often hear C programmers...

C and C++: Freeing PART of an allocated pointer.

Let's say I have a pointer allocated to hold 4096 bytes. How would one deallocate the last 1024 bytes in C? What about in C++? What if, instead, I wanted to deallocate the first 1024 bytes, and keep the rest (in both languages)? What about deallocating from the middle (it seems to me that this would require splitting it into two poin...

jBoss 4.0.2 deploying same WAR multiple times causes jBoss to crash because of PermGem/Out-of-Memory Errors

I develop web applications and I use jBoss 4.0.2 and when I have redeployed my WAR several times with eclipse, jBoss will crash because it runs out of memory. And when I have to install new version to production enviroment, it will consume production servers memory, so that means I have to stop jBoss to prevent redeploying eat memory fro...

iPhone dev - objects stay until user quits, don't release?

In in my app, say it count downs to something and at the end just beeps forever until the user quits the app, is it safe to say have an NSTimer and never release (or in NSTimer's case, invalidate it) it, since it will need to stay until the user quits the app? ...