UIAlertView fails to show and results in “EXC_BAD_ACCESS” error

前端 未结 6 2053
一向
一向 2021-01-21 01:05

A method is called when a return button on the keyboard is pressed. After calling another method which returns an integer a message is created based on that integer. The message

6条回答
  •  抹茶落季
    2021-01-21 01:24

    Objects returned from convenience constructors are already set to autorelease. While you declared a pointer to "message", the "message" object itself doesn't belong to you, since you used the @"string" convenience constructor to create the NSString object. Thus, you don't need to release it.

    When you release it manually, it then gets released too many times (once manually, and once when the autorelease process rolls around) and throws the error.

    Here's some additional information from Apple:

    http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html

    Good rule of thumb: unless you use one of the alloc or init or copy methods to create an object (or if you retain the object yourself) you don't need to release it, but can rely on the method that actually created it to do that work for you.

提交回复
热议问题