Closed gabosgab closed 8 years ago
Does the leak reproduce in the demo app by chance?
I haven't tried, but I imagine it does. I can try later.
Yes, I was able to reproduce the crash that resets the phone. I setup the demo app to open the drawer 161 times and then my iPhone 6 rebooted.
I modified the demo to continuously show to make it easy to test.
- (IBAction)btnShowNotificationPressed:(UIButton *)sender {
[CRToastManager showNotificationWithOptions:[self options]
apperanceBlock:^(void) {
NSLog(@"Appeared");
}
completionBlock:^(void) {
NSLog(@"Completed");
[self btnShowNotificationPressed:sender];
}];
}
Thanks for finding this, I was about to use this library but recreated this crash easily. I can't believe it crashes the whole phone and not just the app.
Welcome, I think it crashes the phone because it leaks memory pages which is more severe since each app is given a finite amount. Good luck!
Sorry, haven't had time to look at it until this morning. Fixed it with changing the CRToastView.h file, there is a strong reference to CRToast and it's causing it to not get released. Changing it to a weak reference fixed it.
@property (nonatomic, weak) CRToast *toast;
Before I couldn't get past ~160 times viewed before it crashed the whole phone but now just ran a test over 1k.
That was probably it, thanks!
On Fri, Apr 22, 2016 at 8:41 AM Chris Jones notifications@github.com wrote:
Also, I couldn't get past ~160 times viewed before but now just ran a test over 1k.
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/cruffenach/CRToast/issues/195#issuecomment-213479584
Hello,
We've been noticing a pretty large memory leak that causes our app to crash pretty often when a number of these are shown during a session user session. We have an app that shows roughly 80-100 of these in a single session and probably stressing it quite a bit. We've seen that this eventually causes the device to hard reset due to either memory leaking or excessive page allocation. We see that roughly 4-8MB are allocated and freed when a notification is shown from the top.
We've profiled this in Instruments and aren't able to catch much because it seems to be rather elusive. We've pulled the library and replaced with a our own and all crashes have stopped.
Here's our usage that resulted in the memory leaks:
`// // POTPopupManager.m // Potion // // Created by Gabe Brown on 10/15/15. // Copyright © 2015 Potion Incorporated. All rights reserved. //
import "POTPopupManager.h"
import "CRToast.h"
@implementation POTPopupManager
@synthesize staticOptions;
/**
@return Instance of POTPopupManager / +(NSMutableDictionary )getOptions {
NSDictionary *staticOptions = @{ kCRToastNotificationTypeKey: @(CRToastTypeNavigationBar), kCRToastNotificationPresentationTypeKey: @(CRToastPresentationTypeCover), kCRToastTextAlignmentKey : @(NSTextAlignmentCenter), kCRToastBackgroundColorKey : [UIColor orangeColor], kCRToastAnimationInTypeKey : @(CRToastAnimationTypeSpring), kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionBottom), kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionTop), kCRToastNotificationPresentationTypeKey: @(CRToastPresentationTypeCover), kCRToastTimeIntervalKey: @(3.0), kCRToastInteractionRespondersKey: @[ [CRToastInteractionResponder interactionResponderWithInteractionType:CRToastInteractionTypeTapOnce automaticallyDismiss:YES block:^(CRToastInteractionType interactionType) { // DO NOTHING } ], [CRToastInteractionResponder interactionResponderWithInteractionType:CRToastInteractionTypeSwipe automaticallyDismiss:YES block:^(CRToastInteractionType interactionType) { // DO NOTHING } ] ] };
NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithDictionary:staticOptions];
return options;
}
/**
Shows the popup on the main thread and calls the callback / +(void)showPopupWithCompletion:(void (^)(void))completion options:(NSMutableDictionary)options {
dispatch_async(dispatch_get_main_queue(), ^{
});
}
/**
+(void)showSuccessPopupWithMessage:(NSString*)message completion:(void (^)(void))completion {
}
/**
@param completion Method called when completed / +(void)showInfoPopupWithMessage:(NSString)message completion:(void (^)(void))completion {
NSMutableDictionary *options = [POTPopupManager getOptions];
[CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor blackColor]; options[kCRToastTextColorKey] = [UIColor whiteColor]; [POTPopupManager showPopupWithCompletion:completion options:options]; }
/**
@param completion Method called when completed / +(void)showInfoPopupWithMessage:(NSString)message completion:(void (^)(void))completion duration:(float)duration {
NSMutableDictionary *options = [POTPopupManager getOptions];
[CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor blackColor]; options[kCRToastTextColorKey] = [UIColor whiteColor]; options[kCRToastTimeIntervalKey] = @(duration);
[POTPopupManager showPopupWithCompletion:completion options:options];
}
/**
+(void)showWarningPopupWithMessage:(NSString*)message completion:(void (^)(void))completion {
}
/**
@param completion Method called when completed / +(void)showErrorPopupWithMessage:(NSString)message completion:(void (^)(void))completion {
NSMutableDictionary *options = [POTPopupManager getOptions];
[CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor colorWithRed:0.59 green:0.04 blue:0.04 alpha:1.0]; options[kCRToastTextColorKey] = [UIColor whiteColor]; [POTPopupManager showPopupWithCompletion:completion options:options];
}
@end`