Stack Exchange
How to release property of static class
i have a static class witch has two property,like below ...
   @interface Global : NSObject
    {

        BarcodeScanner* scanner;
        NSInteger warehouseID;
    }

    @property(assign) BarcodeScanner* scanner;
    @property(assign) NSInteger warehouseID;


    +(Global *)sharedInstance;

    @end


    #import "Global.h"

    @implementation Global
    @synthesize scanner,warehouseID;

    + (Global *)sharedInstance
    {

        static Global *globalInstance = nil;

        if (nil == globalInstance) {
            globalInstance  = [[Global alloc] init];

            globalInstance.scanner = [[BarcodeScanner alloc] init];

            globalInstance.warehouseID = 1;
        }

        return globalInstance;
    }

    -(void) dealloc
    {
        [super dealloc];
    }

@end

now when i analyze project in Xcode i got warning for memory leak for scanner and warehouseID properties , and when i try to release them in dealloc method like ...
[[[Global sharedInstance] scanner]release];

i got warning "incorrect decrement of the reference count of an object..."
how should i resolve this problem.
so thanks for any help.

No need to release. It is auto-releasing object. :)

Oh man, you should never call release on an object's properties directly -> let the object itself manage that memory.

The warning is because your code does not match the rules Analyzer uses.  To avoid the warning

make the scanner property retain
change the the instantiation or BarcodeScanner to be autorelease
add a release for scanner in dealloc

Example (reformatted just to save space):
@class BarcodeScanner;
@interface Global : NSObject {
    BarcodeScanner* scanner;
    NSInteger warehouseID;
}
@property(retain) BarcodeScanner* scanner;
@property(assign) NSInteger warehouseID;

+(Global *)sharedInstance;
@end

@implementation Global
@synthesize scanner,warehouseID;

+ (Global *)sharedInstance {
    static Global *globalInstance = nil;

    if (nil == globalInstance) {
        globalInstance  = [[Global alloc] init];
        globalInstance.scanner = [[[BarcodeScanner alloc] init] autorelease];
        globalInstance.warehouseID = 1;
    }
     return globalInstance;
}

-(void) dealloc {
    [scanner release];
    [super dealloc];
}
@end


just leave it to autorelease pool

globalInstance.scanner = [[[BarcodeScanner alloc] init] autorelease];


That won't work because the property is assign, the BarcodeScanner instance will dealloc on the next drain of the autorelease pool.

yeah.. thanks for correcting me.. property should be made (retain) first. I am very sorry to missed mentioning this part.
