facebookarchive / Shimmer

An easy way to add a simple, shimmering effect to any view in an iOS app.
Other
9.35k stars 1.11k forks source link

Memory issue #52

Closed lionhylra closed 8 years ago

lionhylra commented 8 years ago

I created a view(shimmerView) and added a FBShimmerView onto it. Then I make my app do this loop: Show the shimmerView, go to other views, go to shimmerView, go to other views...

Everything was normal except that something increased in the memory. So I opened Instrument to see what happened. And it showed that instances of FBShimmeringLayer and FBShimmeringMaskLayer increased by one every tine a FBShimmerView is displayed. That means when a FBShimmerView is deallocated, the FBShimmeringLayer is persisted in the memory.
See the screenshot below: screenshot 2015-10-21 17 17 44

grp commented 8 years ago

Do you have the latest commit in place? There was a retain cycle that got fixed: 32ded5bf7bd3a0dbe2f719dbb6e8ef77c3a1d8ee

lionhylra commented 8 years ago

Thanks. I used the package on cocoaPods.

grp commented 8 years ago

I'll put out an update for that soon, but for now you should be able to point Cocoapods to that commit. Thanks for filing!

lionhylra commented 8 years ago

I just use the latest commit and test it in the Instrument. The FBShimmeringLayer and FBShimmeringMaskLayer are still retained. Could you have a check?

grp commented 8 years ago

When you say the instances increase when it is 'displayed', what do you mean by that? Are you asking it to start shimmering? Are you simply adding it to the view hierarchy? Creating a new FBShimmeringView?

I would try limiting the operations you perform on the shimmering view, then go into the one operation that seems to cause the issue and find where it's allocating a new object.

grp commented 8 years ago

I pushed another commit that might help. Let me know if that fixes it.

lionhylra commented 8 years ago

Please see my code below:

@interface LoginViewController()
@property (nonatomic, weak) IBOutlet FBShimmeringView * shimmerView;
@property (nonatomic, weak) IBOutlet UITextField * emailTextField;
@property (nonatomic, weak) IBOutlet UITextField * passwordTextField;
@property (nonatomic, weak) IBOutlet UIButton * loginButton;
@end
@implementation JLPLoginViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self showLogo];
}
-(void)showLogo{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.shimmerView.bounds];
    imageView.image = [UIImage imageNamed:@"logo"];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.shimmerView.contentView = imageView;

    // Start shimmering.
    self.shimmerView.shimmering = YES;
}
@end

What I did is:

  1. I instantiate the LoginViewController from storyboard in '- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions', and assign it to the rootViewController of main window
  2. When the login button is tapped, I instantiate another view controller and assign to the rootViewController of main window. At this moment, the LoginViewController should have been deallocated.
  3. When the logout button is tapped, instantiate a LoginViewController and assign it to the rootViewController of main window again. At this moment, the FBShimmeringLayer of previous LoginViewController is not deallocated and a new instance of FBShimmeringLayer is created for the new LoginViewController.
lionhylra commented 8 years ago

After trying the last commit, I find the issue is still there.
screenshot 2015-10-22 11 38 17 screenshot 2015-10-22 11 38 36

grp commented 8 years ago

Unfortunately, you'll have to debug this yourself. It may be due to the specifics of how you're using Shimmer.