EXC_BAD_ACCESS right after touchesBegan

I have started a very simple project to learn iOS programming, but I get EXC_BAD_ACCESS after touchesBegan.

You can download the project from DropBox here .

  • iPhone private API compiling
  • SourceKitService Terminated
  • How would I use polymorphism to allow a method to accept multiple classes, but with IBOutlets?
  • XCode 4.4 .strings file add new localization option gone
  • null / nil in swift language
  • firebase iOS not receive push notifications
  • I basically have a UIView subclass that should draw circles wherever the user is touching.

    Very simple but I cannot make it work.

    Any help is highly appreciated.
    Thanks!

    EDIT
    Turns out the problem is this line of code in touchesBegan:

        ts = [NSMutableSet setWithSet: [event touchesForView:self]];
    

    That I changed into:

        ts = [[NSMutableSet setWithSet: [event touchesForView:self]] retain];
    

    3 Solutions Collect From Internet About “EXC_BAD_ACCESS right after touchesBegan”

    Why don’t you use ARC??? 🙂 Its good! You do not retain your ts set. Note, that setWithSet: returns you autoreleased instance. (The red circle looks promising :))

    BAD_ACCESS errors are generally related to referencing objects that no longer exist (i.e. they were deallocated or they were autoreleased). Check for these issues inside touchesBegan or touchesEnded:

    1. Any incorrect placement of release calls, when an object is still going to be used. Try commenting them out and see if the error is gone.
    2. Using autoreleased objects and not retaining them. Autoreleased objects are the ones created using the method names that refer directly to the class, like these: [NSString stringWith...] or [NSArray arrayWith...], instead of using alloc and init.

    For further help, please try to include some code snippets for these methods.

    To know the reason of BAD_ACCESS use Zombie in xCode, check the link
    http://www.markj.net/iphone-memory-debug-nszombie/