Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Advanced Objective-C Memory Management

AHMET GÜLERER
AHMET GÜLERER
1,597 Points

Why still weak reference is there???

Please look at the code and tell me why weakArray is still there?

import <Foundation/Foundation.h>

@interface clsAhmet : NSObject

@property (nonatomic,weak) NSArray *weakArray; @property (nonatomic,strong) NSArray *strongArray;

-(void) calis;

@end

import "clsAhmet.h"

@implementation clsAhmet

-(void) calis

{ self.strongArray = @[@"strongArray1",@"strongArray2"];

self.weakArray = self.strongArray;



self.strongArray = nil;

if(self.weakArray != nil)
{
    NSLog(@"weakArray halen nil degil");
}

}

@end

output:

2014-06-25 01:03:52.545 StrongvsWeak[2216:303] weakArray halen nil degil Program ended with exit code: 0

2 Answers

You should use this code

self.weakArray = [[NSArray alloc] initWithArray:self.strongArray];

Instead of this code

self.weakArray = self.strongArray;
AHMET GÜLERER
AHMET GÜLERER
1,597 Points

Thanks for answer. That is useful.