Missing dealloc?


#1

Hi!
It’s my second post, sorry for my Joda english :stuck_out_tongue:

I have a problem with BMITime project modifications for this chapter.

When i run the project, my console show this:

2012-06-05 14:37:39.029 BMITime[11877:403] Employees: ( "<Employee 0: 0 in assets>", "<Employee 1: 153 in assets>", "<Employee 2: 119 in assets>", "<Employee 3: 68 in assets>", "<Employee 4: 0 in assets>", "<Employee 5: 136 in assets>", "<Employee 6: 119 in assets>", "<Employee 7: 34 in assets>", "<Employee 8: 0 in assets>", "<Employee 9: 136 in assets>" ) 2012-06-05 14:37:39.031 BMITime[11877:403] Giving up ownership of one employee 2012-06-05 14:37:39.032 BMITime[11877:403] Giving up ownership of array

My output is not like in the book, and i can’t get deallocating information.

My code:
main.m

[code]//
// main.m
// BMITimem
//
// Created by on 24/05/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>
//#import “Person.h”
#import “Employee.h”
#import “Asset.h”

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    // Create an array of Employee objects
    NSMutableArray *employees = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < 10; i++) {
        // Create an instance of Employee
        Employee *person = [[Employee alloc] init];
        
        // Give the instance variables interesting values
        [person setWeighInKilos:90+i];
        [person setHeighInMeters:1.8 - i/10.0];
        [person setEmployeeID:i];
        
        // Put the employee in the employees array
        [employees addObject:person];
    }
    
    // Create 10 assets
    for (int i = 0; i < 10; i++) {
        // Create an asset
        Asset *asset = [[Asset alloc] init];
        
        // Give it an interesting label
        NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d", i];
        [asset setLabel:currentLabel];
        [asset setResaleValue:i * 17];
        
        // Get a random mumber between 0 and 9 inclusive
        NSUInteger randomIndex = random() % [employees count];
        
        // Find that employee
        Employee *randomEmployee = [employees objectAtIndex:randomIndex];
        
        // Assign the asset to the employee
        [randomEmployee addAssetsObject:asset];
    }
    
    NSLog(@"Employees: %@", employees);
    
    NSLog(@"Giving up ownership of one employee");
    
    [employees removeObjectAtIndex:5];
    
    NSLog(@"Giving up ownership of array");
    
    employees = nil;
}
return 0;

}

[/code]

Asset.h

[code]//
// Asset.h
// BMITime
//
// Created by on 28/05/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Asset : NSObject
{
NSString *label;
unsigned int resaleValue;
}

@property (strong) NSString *label;
@property unsigned int resaleValue;

@end

[/code]

And finaly Asset.m

[code]//
// Asset.m
// BMITime
//
// Created by on 28/05/12.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import “Asset.h”

@implementation Asset

@synthesize label, resaleValue;

-(NSString *)description
{
return [NSString stringWithFormat:@"<%@: $%d >",
[self label], [self resaleValue]];
}

-(void)dealloc
{
NSLog(@“deallocating %@”, self);
}

@end

[/code]

Any idea?

Thanks.


#2

Do you have ARC turned on? Are you on Xcode 4.2 or later?


#3

Thanks for quick reply.
I activated ARC, and works fine now.

Best regards.