Returning objects from methods in Objective-C

Please explain how to handle returned objects from methods?

Below I get employee details from the GeEmployeetData function with auto-advertisement,

  • Do I need to save the returned object in the process method?
  • Can I free * emp in a Process function?

    - (void) Process {Employee * emp = [self GeEmployeetData]}

    + (Employee *) GeEmployeetData {

    Employee * emp = [[Employee alloc] init]; // fill the object

    return [emp autorelease]; }

+3
source share
1 answer

In 99% of cases, you must save objects with auto-implementation returned from other methods if you want to save them.

, , release. 99% , retainCount , 1 .

+4

Source: https://habr.com/ru/post/1743447/


All Articles