views:

78

answers:

0

I tried 2 different methods of creating a background image for a view controller.

I have researched this before and came to the conclusion that for good memory practice you should use this method:

NSString *path = [[NSBundle mainBundle] pathForResource:@"controllerBackground" ofType:@"png" inDirectory:@""];

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]]];

When using the other method:

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"controllerBackground.png"]]];

This is not as efficient as using the imageWithContentsOfFile:path method.

However when testing both these methods using the performance tools "leak" monitor, I observed a very unusual thing happening.

While using the imageWithContentsOfFile:path method, the problem was that when going back and forth within a navigation controller loading the view controller, the memory would keep increasing within the vicinity of approximately 1mb every time the view controller loads.

This problem is also only observed in the new iOS 4.1 and 4. It does not seem to happen in the iOS 3.0 or 3.2.