memory-management

memory management with outlets and properties in view controllers

Hey guys, sorry for beating the memory management (dead)horse again. I know this question has been asked several times on SO, but I feel all the threads out there is still lacking two pieces of information. Let me put forth what I DO know to save everyone some time. 1) When you create an IBOutlet, your view controller automatically reta...

objective C (iphone) question about releasing

If I create a view, and add it as a subview and also add it to an array, do I have to release it twice? UIView* cat = [[UIView alloc] initWithFrame:someFrame]; [self.view addSubview:cat]; [self.animals addObject:cat]; [cat release]; [cat release]; It just seems weird to me to have 2 release statements, and I haven'...

How to properly release assigned object with no handle.

Instruments is pointing out that this is a memory leak, however I'm unsure how to release it properly, or when it should be released. Is there a better convention for assigning properties with new objects that are only needed inside a loop? The specific line is the "expense.addedDate = [NSDate new];". - (void) addObjects:(NSString *)it...

iPhone - Why do I get a leak ?

I get a leak on the code below, any idea why? I am not allocating anything so why does it leak? It leaks 32 bytes NSString *username = @""; NSString *myString = @"some text"; NSRange range = [myString rangeOfString:@"username="]; //instrument shows a leak on the line below username = [myString substringToIndex:range.location + range.le...

Memory management - C# VS Objective C ??

SO I already know about memory management in objective C, and I never had to know about it while programming in .net (C#). But i still have some questions about how everything is done. -Why does the code leak in objective c if we allocate an object and not release it? -Why doesn't this leak in C#? -What are some advantages and disadva...

Getter and setter and property retain in objective-c

Hi all, I have a class wich is initialized like this. // myclass.h @property(nonatomic,retain) NSMutableArray *daysOfWeek; // this is in .h file // myclass.m @synthesize daysOfWeek; -(id)init { if(self=[super init]) { // initialize days of week self.daysOfWeek = [NSMutableArray arra...

How could I sensibly overload placement operator new?

C++ allows overloading operator new - both global and per-class - usual operator new, operator new[] used with new[] statement and placement operator new separately. The former two of those three are usually overloaded for using customized allocators and adding tracing. But placement operator new seems pretty straightforward - it actual...

iPhone Memory Management

Hello Stackoverflow fellow family members! I've got question regarding memory management in iPhone. What I did understand was below method -(void) dealloc { // something else to release whatever // such as Object Created using keyword 'alloc' // but also Object destroy here its retain value reaches iff 0 // if I do put...

Can I use global operator new for a class having operator new overloaded?

Suppose I have a class with overloaded operator new. class Class { public: void* operator new( size_t ); void operator delete( void* ); }; Will objects of that class always be allocated with the overloaded operator new when I use new Class() or is it possible that the default operator new is used when new Class() construct appea...

Memory Layout of application

Hi, The following question is a head-scratcher for me. Assuming that I have two platforms with an identical hardware, the same OS and the same compiler on it. If I compile exactly the same application, can I be sure that the memory layout on both machines will exactly be the same? In other words, both applications have exaclty the same ...

Where can I find a c++ memory allocator testbed?

Possible Duplicate: Benchmarks used to test a C and C++ allocator? Hello all, I've recently written an STL compatible custom allocator + memory manager, and I need a good (preferably multi-threaded) testbed to verify that it's working correctly. I could roll my own, but I imagine there are pretty good ones out there that hav...

Usages of object resurrection

I have a problem with memory leaks in my .NET Windows service application. So I've started to read articles about memory management in .NET. And i have found an interesting practice in one of Jeffrey Richter articles. This practice name is "object resurrection". It looks like situating code that initializes global or static variable to "...

didReceiveMemoryWarning called but not viewDidUnload?

I'm running into a situation where didReceiveMemoryWarning is being called but viewDidUnload is not. The docs for didReceiveMemoryWarning say: The default implementation of this method checks to see if the view controller can safely release its view. This is possible if the view itself does not have a superview and can be reloaded ei...

Deallocate Memory in PHP

I have a script that is transferring about 1.5 million rows (~400mb worth of data) from a table to another table (during this process, some data is converted, modified, and placed in the correct field). It's a simple script, it just recursively loads data, then places it in the new tables under the correct fields and formats. The scripts...

When to release a UIView that is removed from superview

I am creating a loading screen UIView which is added to a subview while some XML is parsed from some URL. Once the XML is returned, the loading screen is removed from its superview. The question I have is how should I release this object? In the code below, you'll see that I send removeFromSuperview to the loadingScreen, but I still h...

"[CALayer release]: message sent to deallocated instance" when dismissing modal view controller

Hello, I've been struggling with this for last few days and I cannot find any solution, so I ask you for advice. I have two UIViewControllers: NewPostUIViewController and SettingsUIViewController. In the second one I have a field: id<SettingsUIViewControllerDelegate> delegate and the first one implements protocol SettingsUIViewCont...

Objective C property retain count

if I have a property such as @property (nonatomic, retain) NSArray *myArray; and then I set it as follows [self setMyArray:[[NSArray alloc]init]]; do I have a retain count of 2? When I release it in my dealloc method will there still be a retain count of 1? ...

Why 16-bit address with 12-bit offset results in 4KB page size?

Hi guys, I'm reading the "Modern Operating System" book. And I'm confused about the "Page Size". In the book, the author says, The incoming 16-bit virtual address is split into a 4-bit page number and 12-bit offset. With 4 bits for the page number, we can have 16 pages, and with 12 bits for the offset, we can address all ...

Sandboxing vs. Virtualisation

Hi all, Maybe I am missing something but isn't sandboxing and virtualisation exactly the same concept, ie., separating the memory space for applications running in parallel. So I am wondering why they are having different names, are there maybe differences in the way they are employed? Many thanks, Simon ...

"pointer being freed was not allocated" Memory block will not deallocate for some reason.

Hello. I'm struggling to find why I can't free a memory block. Something must be wrong with the pointer. A memory block for a structure is made in a function and the pointer used is stored in an array. Later the pointer is taken from the array to be used to free the memory. I've figured out which free it is. I've placed "//This one" nex...