problem about unsafe-unretained-Collection of common programming errors


  • Anders Sjöqvist
    ios objective-c automatic-ref-counting objective-c-runtime unsafe-unretained
    I’m new to Objective-C and ARC, and have been searching and reading for hours without finding an answer. The code does what I want it to do, but I want to know that it doesn’t rely on favorable conditions. Here’s a simplified version of my code:+(void)foo {Class *classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * someValue);// Perform work without complicated memory managementfree(classes); }I can’t do much about the structure I’m allocating. It’s filled by objc_getClassList. Unfortun

  • MattDiPasquale
    objective-c automatic-ref-counting retaincount unsafe-unretained
    Let’s say I want to create a temporary variable, e.g.:To point to another long-living variable:__unsafe_unretained UIView *tableHeaderView = self.tableView.tableHeaderView;To point to an object I just created.__unsafe_unretained UIView *tableHeaderView = [[UIView alloc] init];These temporary variables don’t need to be retained because the objects they point to are guaranteed to keep positive retain counts for as long as the temporary variables are in scope. So, should I declare them as __unsafe_

  • Pang
    objective-c automatic-ref-counting unsafe-unretained
    Problem:I have an __unsafe_unretained id pointer that points to an already released object. So far so good, as long as I do not “use” the pointer at all (in particular, I do not call any method through the pointer). However, when I try to return its value from a method, it crashes, even if I have explicitly specified that the return value has the type __unsafe_unretained id. Why is that? I thought if I use __unsafe_unretained, it would not call methods like retain / release / autorelease at all?

Web site is in building