facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.93k stars 2.01k forks source link

Continuous memory increase (memory leak) when using infer with xcodebuild #1753

Open elhoangvu opened 1 year ago

elhoangvu commented 1 year ago

Hi everyone,

monitor

Sample code

Used command

infer run -- xcodebuild clean build -project fbinfer-memoryleak.xcodeproj -scheme fbinfer-memoryleak -sdk iphonesimulator

Sample code

#import <Foundation/Foundation.h>

@interface Builder: NSObject

@property (nonatomic, readonly) Builder * (^next)(void);

@end

@implementation Builder

- (Builder* (^)(void))next {
    return ^Builder * {
        NSLog(@"Do something");
        return self;
    };
}

@end

void infer(void) {
    Builder* builder = [[Builder alloc] init];
    builder
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next()
        .next();
}

The project uses an Objective-C class with block method style. The instance calls these methods chainingly, resulting in 15 chains. However, Infer capture by xcodebuild is stuck when compiling Infer.m which causing continuous memory increase (up to 20 GB and continuously increasing) until the device shuts down.

Using the next block with 14 chains consumes about 10GB of memory, while using 13 chains consumes about 5GB of memory. The program runs successfully without any memory issues.

More Info

Infer

Xcode

Device

mac-2018

mac-2020

Hopefully, the Infer development team will resolve this issue soon. Thank you very much.