Manual retain/release/autorelease instead of ARC

ID

objectivec.portability.manual_memory_management

Severity

low

Remediation Complexity

hard

Remediation Risk

medium

Remediation Effort

high

Resource

Memory Management

Language

Objective-C

Description

This file manages memory by hand - retain, release or autorelease sent explicitly - which only compiles with ARC turned off. Manual reference counting has to be kept balanced by the author on every path, so it leaks or over-releases as soon as the code changes, and the file cannot be moved to a target built with -fobjc-arc. Convert the file to ARC (Edit > Convert > To Objective-C ARC) and delete the ownership calls. A release guarded by a nil check is also reported, more specifically, by unnecessary-nilcheck-dealloc.

Rationale

This file manages memory by hand - retain, release or autorelease sent explicitly - which only compiles with ARC turned off. Manual reference counting has to be kept balanced by the author on every path, so it leaks or over-releases as soon as the code changes, and the file cannot be moved to a target built with -fobjc-arc. Convert the file to ARC (Edit > Convert > To Objective-C ARC) and delete the ownership calls. A release guarded by a nil check is also reported, more specifically, by unnecessary-nilcheck-dealloc.

The following code illustrates the pattern detected by this rule:

@implementation LegacyStore

- (void)refreshWithItems:(NSArray *)items {
    // FLAGGED: Manual retain/release/autorelease instead of ARC
    [[self view] retain];
    // FLAGGED: Manual retain/release/autorelease instead of ARC
    [self.observer release];
    // FLAGGED: Manual retain/release/autorelease instead of ARC
    [items autorelease];

    // A commented-out release is not code: it is the control for the comment guard.
    // [_oldThing release];

    /* [_blockCommented release]; */

    NSString *note = @"send [thing release] when done";

    // `retainCount` is a different selector and must not be reported.
    NSUInteger n = [self.observer retainCount];

    id first = items[releaseIndex];

    self.observer = nil;

    NSLog(@"%lu %@ %@", (unsigned long)n, note, first);
}

@end

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved