From c8f808d09529cfcdccad070d5782820309e99770 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Thu, 3 Nov 2011 15:30:15 +0000 Subject: [Author: thomasvl] Fix memory model by making all the outlets assign not retain. The problem here is UIViewControllers will dump their view in low memory and then reload next time it is needed. So someone hangs on to the localizer for something else, it would keep the views also loaded, so this way the localizer won't keep any of the objects it points to alive via a retain. Note: the AppKit version sorta matches this since outlets aren't retained by default. Clear them in awakeFromNib since that is all they are needed for. R=dmaclach DELTA=19 (9 added, 0 deleted, 10 changed) --- iPhone/GTMUILocalizer.h | 6 +++--- iPhone/GTMUILocalizer.m | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'iPhone') diff --git a/iPhone/GTMUILocalizer.h b/iPhone/GTMUILocalizer.h index 3d5552b..d34c4d0 100644 --- a/iPhone/GTMUILocalizer.h +++ b/iPhone/GTMUILocalizer.h @@ -65,9 +65,9 @@ id yetAnotherObjectToLocalize_; NSBundle *bundle_; } -@property(retain) IBOutlet id owner; -@property(retain) IBOutlet id otherObjectToLocalize; -@property(retain) IBOutlet id yetAnotherObjectToLocalize; +@property(nonatomic, assign) IBOutlet id owner; +@property(nonatomic, assign) IBOutlet id otherObjectToLocalize; +@property(nonatomic, assign) IBOutlet id yetAnotherObjectToLocalize; - (id)initWithBundle:(NSBundle *)bundle; diff --git a/iPhone/GTMUILocalizer.m b/iPhone/GTMUILocalizer.m index 274eb04..efebc42 100644 --- a/iPhone/GTMUILocalizer.m +++ b/iPhone/GTMUILocalizer.m @@ -47,15 +47,20 @@ } - (void)awakeFromNib { - if (owner_) { - NSBundle *newBundle = [[self class] bundleForOwner:owner_]; + id owner = self.owner; + if (owner) { + NSBundle *newBundle = [[self class] bundleForOwner:owner]; bundle_ = [newBundle retain]; - [self localizeObject:owner_ recursively:YES]; - [self localizeObject:otherObjectToLocalize_ recursively:YES]; - [self localizeObject:yetAnotherObjectToLocalize_ recursively:YES]; + [self localizeObject:self.owner recursively:YES]; + [self localizeObject:self.otherObjectToLocalize recursively:YES]; + [self localizeObject:self.yetAnotherObjectToLocalize recursively:YES]; } else { - _GTMDevLog(@"Expected an owner_ set for %@", self); + _GTMDevLog(@"Expected an owner set for %@", self); } + // Clear the outlets. + self.owner = nil; + self.otherObjectToLocalize = nil; + self.yetAnotherObjectToLocalize = nil; } + (NSBundle *)bundleForOwner:(id)owner { -- cgit v1.2.3