Does an object free an object from destroying an object?

I am new to cocoa -touch and really unmanageable languages. Although I have a solid understanding of the syntax, I wonder if I am freeing the object correctly.

I have a view that creates an object,

Communication *comm = [[Communication alloc] init];
[comm doSomething];
[comm release];

I understand that I need to destroy this object because I select it and it will not be automatically released.

I call a method on an object that goes to my server and grabs the information. When the data is returned, it throws an event that my message manager responds to. I do not want to destroy the object until it returns from the server - and in this I am embarrassed.

  • If I free this object right after I make the call, will it destroy the object? (What I do not want to do.)
  • How to destroy this object after it throws an event with the data that I'm waiting for? This will happen in an event DataFinishedLoadingat my facility comm. If he destroys himself, and is this the right way to do it?

The view calling my object essentially says: create this object, call this method and go about your fun path. He does not care what happens after he calls the method - whether it returns information or not. It just listens for the method for any data that may appear later. I have no reason to hang on the link to the object, since I will never use the same instance after I make the call - in addition, cleaning after myself.

+3
source share
2 answers

A release , .

, , Communication. . . / , ( dealloc ).

, retainCount. , 1. retain , release . autorelease , . 0 Objective-C, , ( dealloc). : retainCount, . , alloc/copy/new/retain release/autorelease .

+3

comm release. - , doSomething.

, - , . , , nil, .

+2

All Articles