I manage to solve the issue by Initializing MBProgressHUB only a single time in the AppDelegate. And use only a reference to that in other places
Memory leak when using MBProgressHUD
-
21-06-2023 - |
Pregunta
I am using the MBProgressHUB
as the loading indicter. I noticed via Instruments, There's considerable memory leak when using MBProgressHUB
( Around 3MB each time its initiate. And issue is, memory DOES NOT clear when the view unload ).
Project is ARC enabled
This is how I am initiate MBProgressHUB
in ViewDidLoad
(HUD is retained property too)
HUD = [[MBProgressHUD alloc] initWithView:[(AppDelegate *)[[UIApplication sharedApplication] delegate] window]];
[[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] addSubview:HUD];
HUD.delegate = self;
Also in the ViewDidUnload
I am setting HUD = nil;
Any ideas???
Solución 2
Otros consejos
You are adding your hud to the window as subview. Window holds it in subviews all the time your app is running.
You should call [HUD removeFromSuperview] method when you don't need it or set property HUD.removeFromSuperViewOnHide to YES - so it will remove itself on hiding and deallocate the memory if you are not retaining it elsewhere.
If you added it to the controller's view - it would be deallocated in the end of controller's lifecycle with its view.
Im doing this with a non-ARC project.
I found a solution just changing the - (id)initWithView:(UIView *)view {
method. It returns me
and i changed it to return [me autorelease]
Regards