0

Is something like this is not a memory leak or other issues?

- (void) requestAndUpdateView: (UIViewController *) vc {

    [afHttpManager POST:....
            success:^(....){ [vc doSomething]} ...
    ...
    ];


}
Aviah Laor
  • 3,620
  • 2
  • 22
  • 27

1 Answers1

1

No it is not a memory leak, because vc has not been created in this scope, so you should not manage it's retain count in it.

However your code reveals another issue : be sure to perform every UI modification on the Main thread otherwise you will experience random crash.

EDIT Asked for more details :

Every UI action should be made on the App's Main thread. In Cocoa touch, your application is attached to main thread. Application's main event loop receives UI events. Using another thread (background threads) to change anything that is graphic is a bad idea because the UIKit is not thread safe.

My guess is that afHttpManager does it's work in another thread to avoid freezing the App's UI, so any code executed will be on the same thread than your afHttpManager.

TheSquad
  • 7,385
  • 8
  • 40
  • 79
  • Thanks, can you please explain what UI modification, and why the random crash? Or this may crash if the app looses focus to another app, and then AFNetworking tries to call the view? any better ways to avoid it? – Aviah Laor Feb 07 '15 at 16:18
  • @user61152 I have edited my answer to add more details – TheSquad Feb 07 '15 at 16:26
  • Based on the following answer, the success block runs on the main queue, to it seems safe after all? http://stackoverflow.com/questions/17225193/are-afnetworking-success-failure-blocks-invoked-on-the-main-thread – Aviah Laor Feb 07 '15 at 16:42
  • If it is then you have nothing to worry about... I never user afHttpManager so I just wanted to give you a heads up. – TheSquad Feb 07 '15 at 16:43