views:

155

answers:

2

Hello,

How to "clean" static int variables in a view class method? Every time a get back to this view I need those vars "zeroed". The [self.view removeFromSuperview]; instruction does not seem enough to free up memory from those vars.

Thank you. Have a great 2010!

These int vars are declared static in a view method. They are not global in the view class.

A: 

You'll have to manually do this by defining a setValue method similar to:

@interface MyClass 
{
  // ...
}
+ (NSString *)myVar;
+ (void)setMyVar:(NSString *)newVa;
@end

@implementation MyClass
static NSString *myVar;
+ (NSString *)myVar { return myVar; }
+ (void)setMyVar:(NSString *)newVar { myVar = newVar; }
@end
ennuikiller
This works like class global vars. What I'm looking for are view method static local vars that stick around while on that view and after leaving it they are released. When back, they are renewed and consequently zeroed. Thanks.
BigJoke
+1  A: 

If you don't want a static value to stick around, don't make it static.

jbrennan
That's a point. I want the static values to stick around as long as I'm on their view. Right after going away from that view..puff, their gone. When I get back to their view, I want them already "zeroed". Like local vars. These int vars are declared static in a view method. They are not global in the view class. Thanks.
BigJoke
It sounds like you're looking for instance variables. If you keep your view around even after it's disappeared, why not just zero the instance variables in `-viewWillAppear:` or `-viewDidDisappear`?
jbrennan