After a gesture B is added to view a, view a Will rehold gesture B.
Therefore, if this gesture B is global, you should remove gesture B when releasing view A. Otherwise, gesture B cannot be release.
Of course, if we use gestures like the following, we do not need to remove this gesture when releasing view.
MVI = [[msviewalloc] initwithframe: cgrectmake (50,150,100,
(100)];
Uitapgesturerecognizer * tapgue = [[uitapgesturerecognizeralloc] initwithtarget: selfaction: @ selector (tapedcalled :)];
[MVI addgesturerecognizer: tapgue];
[Tapgue
Release];
This is because the gesture is only given to retain by the MVI. If the MVI is release along with the program, the gesture will also be release. Therefore, as long as the MVI is not released, this gesture will not be released, which must be remembered.
If multiple views share one gesture, you should be more aware of the retaincount of the gesture to prevent the memory from being released.
During the test, instruments was used for observation,
After an execution is added to a uiview, unless otherwise required
[MVI removegesturerecognizer: tapgue];
Operation, and there will be no memory leakage error,Estimated to beThis is because when a uiview such as MVI is dealloc, all the gesture objects added to it will be released. So there will be no memory leakage. In other words, it is of little significance to execute removegesturerecognizer if it is not particularly necessary.
To verify the above statement, it is easier to continue with a gesture class. Then I wrote a class to directly inherit uitapgesturerecognizer and only implement one method, that is, dealloc {
Nslog (@ "gesture dealloc ");
[Super dealloc];
}
Then add it to MVI, regardless of whether the execution is performed [MVI removegesturerecognizer: tapgue];
In this method, we found that the gesture method dealloc will be called when MVI release and dealloc are executed.
Therefore, it can be confirmed that when a class such as uiview is dealloc, the underlying layer executes an operation to remove all gestures. In this way, all the gestures added above will be released.