Am I responsible for releasing the UIView gesture tag in dealloc?

I connected the UIGestureRecognizer to the UIView. Whose responsibility is to free him during dealloc?

In particular:

UITapGestureRecognizer *t = [[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(tapHandler:)]; [self.view addGestureRecognizer:t]; [t release]; 

Thus, self.view currently has a unique Recognizer gesture retention.

Update I should have been clearer. My question is related to the dealloc views method. Does supervision of the view of the view issue gestureRecognizer when the view is released. Currently, I assume this is so.

+6
memory-management ios uigesturerecognizer
source share
2 answers

The rule of thumb is that you call release every time you call alloc , new or copy .

Since you called alloc, your code does not re-issue or skip anything.

As long as you can automatically recognize your gesture recognizer, I would not want to, because explicitly freeing objects where possible is better memory management. (Authorized objects are not freed until the auto-calculation pool is deleted.)

+1
source share

The correct code.

View takes responsibility for the gestures recoginzer with [self.view addGestureRecognizer:t] .

You can organize your code by performing t auto-implementation when you create it:

 UITapGestureRecognizer *t = [[[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(tapHandler:)] autorelease]; [self.view addGestureRecognizer:t]; 

This would mean that all ownership of t processed in one place, which reduces the likelihood of problems if the code is modified.

+2
source share

All Articles