memory-management

Are there any more methods than dataFromPropertyList:format:errorDescription: which do not follow the basic rules of the object ownership policy?

Like Apple says, the dataFromPropertyList:format:errorDescription: method does not follow the object ownership policy. The method reference describes it. I have tried to search for "need to be released by the caller", but no useful results. Here's a quote from the reference: Special Considerations Unlike the normal memory manageme...

Why should I send -autorelease to my instance variable in my setter method, rather than -release?

Apple is doing this in a setter method for an instance variable mainSprocket: – (void)setMainSprocket:(Sprocket *)newSprocket { [mainSprocket autorelease]; mainSprocket = [newSprocket retain]; return; } Why do they send -autorelease and not -release? Would a -release have a bad effect here? Actually it should not (for my u...

Autorelease and "assign" properties in Objective-C? (On iPhone)

I have an instance of a UITableView, and a separate class that adheres to the delegate and datasource protocols. I'm doing this like so: SubjectTableViewHandler *handler = [[[SubjectTableViewHandler alloc] init] retain]; tv.delegate = handler; tv.dataSource = handler; [handler autorelease]; I don't want to maintain the handler as an i...

Retain Cycles: Why is that such a bad thing?

There are two Objects A and B. A creates B and retains it. B has an instance variable that points to A, retaining it. So both retain eachother. Some people say, that this strong connection can't be broken ever again. But is that really the case? If B would release A, then A could easily release B, and so B would be deallocated. A would...

Why don't purely functional languages use reference counting?

In purely functional languages, data is immutable. With reference counting, creating a reference cycle requires changing already created data. It seems like purely functional languages could use reference counting without worrying about the possibility of cycles. Am is right? If so, why don't they? I understand that reference counting i...

Will the -dealloc method be called upon application quit?

Apple says, that in Cocoa -dealloc will not be called neccessarily when the application quits. Does this also apply to the iPhone? ...

Does a collection send a -release message to all objects it holds, if I send it an -release?

I've been reading that if an collection "gets released" it releases all it's objects as well. On the other hand, I was also reading that a collection would release it's objects as soon as the collection gets deallocated. But the last thing may not always happen, as apple says. The system decides if it's good to deallocate or not. In mos...

Are memory mapped files bad for constantly changing data?

I have a service that is responsible for collecting a constantly updating stream of data off the network. The intent is that the entire data set must be available for use (read only) at any time. This means that the newest data message that arrives to the oldest should be accessible to client code. The current plan is to use a memory ma...

How are objects in an autorelease pool referenced?

I am wondering if the autorelease pool holds strong or weak references to the objects it holds. I would guess they are weak. When I add an object to an autorelease pool, it's just not immediately released but will be released when the pool is drained, right? So the references should be weak, i.e. the reference count (or retain count) kee...

What's the difference between sending -release or -drain to an Autorelease Pool?

In many Books and on many Sites I see -drain. Well, for an Autorelease Pool that sounds cool. But does it do anything other than an release? I would guess -drain just makes the Pool to -release all it's objects, without releasing the Pool itself. Just a guess. ...

Where are all the pre-installed autorelease pools in iPhone applications?

I am wondering how many there are, and where they are. As I have seen in a Stanford Vid, there is one autorelease pool installed in the event loop of an iPhone App. But I think I missed the point where exactly that is? And are there any other autorelease pools that I should know about? ...

Should I -drain or -release an autorelease pool in iPhone OS?

The doc says: In a garbage-collected environment, sending a drain message to a pool triggers garbage collection if necessary; release, however, is a no-op. In a reference-counted environment, drain has the same effect as release. Typically, therefore, you should use drain instead of release. If I get that right, they ...

Mark phase misdetection on garbage collection for C

Hello, I've looked at Conservative GC Algorithmic Overview Can a misdetection happen in the 'marking' part? If some data is stored and by coincidence happen to be the same as an address of an allocated memory, will the collector keep the memory ? ...

do I need to explicitly alloc my NSNumber?

I am defining a number, as follows: NSNumber *nn0 = [NSNumber numberWithInt:0]; It works fine without any alloc. My understanding is that if I use numberWithInt, alloc and init are called automatically. If I try to release at the end of my function, I run into problems: [nn0 release]; I get a runtime error. My question is: if I us...

Why should a self-implemented getter retain and autorelease the returned object?

Example: - (NSString*) title { return [[title retain] autorelease]; } The setter actually retained it already, right? and actually nobody should bypass the Setter... so I wonder why the getter not just returns the object? It's actually retained already. Or would this just be needed in case that in the mean time another objects get...

Why do the variables behave so strange?

I thought an variable in objective-c is just a reference to an object somewhere in memory. So for my understanding, the result must have been "one", because at the end i assign the object's memory address of str1 to str2, and previously I had assignend the memory adress of str2 to test. NSString *str1 = [NSString stringWithCString:"one"...

Objective-C on iPhone release problem

I have a problem that I am getting EX_BAD_ACCESS when calling release on an NSStream object in my dealloc on the iPhone. The following code - (void)dealloc { DLog(@"dealloc started for: %@",self); @synchronized(self) { lookupCount--; if (lookupCount==0) { UIApplication* app = [UIApplication sharedApplication]; app.ne...

libraries/approaches for implementing object models in C++

Apologies if this has been asked before, I'm not quite sure of the terminology or how to ask the question. I'm wondering if there are libraries or best practices for implementing object models in C++. If I have a set of classes where instances of these classes can have relations to each other and can be accessed from each other via vari...

Why should I write [anView release], anView = nil; rather than [anView release]; ?

Somewhere I was reading that - regarding low memory warnings and giving up an non-visible view with all it's subviews (= a whole nib, I think), you should do that: -(void)dealloc { [anView release], anView = nil; [someImageView release], someImageView = nil; [super dealloc]; } rather than -(void)dealloc { [anView rel...

iPhone - Most memory effecient way to initialize an image?

Hi I've read that imageNamed: is bad when trying to initialize images. But then what is the best way? I am using imageWithContentsOfFile: and passing the path of an image in my resources folder [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"] This call is made some 30 times in a for loo...