views:

90

answers:

1

I have two tableviews. One loads when I select one tab, and the other loads when I select the other tab.

I use MBProgressHUD to allow for quick switching between the tabs as I pull the tableview datasource from the web using Objective Resource and that can take a little bit. So I throw up a HUD progress indicator waiting for the data to load.

This in turn has allowed me to quickly switch between tabs. But.... If I do it quick enough an exception occurs

EXC BAD ACCESS

with NSZombiesEnabled I get this: 2010-08-02 22:44:43.116 Film Fest[962:8703] * -[MBProgressHUD release]: message sent to deallocated instance 0x85490b0

In both my tableviews I use two different custom tableviewcells.

What should be my next step to debug this?

... so I have moved the code to create the HUD from my viewWillAppear: method to viewDidLoad: and the crash went away. // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)

HUD = [[MBProgressHUD alloc] initWithView:self.view];

    //HUD.graceTime = 0.5;
    //HUD.minShowTime = 5.0;

    // Add HUD to screen
    [self.view addSubview:HUD];

    // Register for HUD callbacks so we can remove it from the window at the right time
    HUD.delegate = self;

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(loadFilms) onTarget:self withObject:nil animated:YES];

however this doesn't really fix my issue as viewDidLoad only occurs once in a long while especially with the new multitasking. I need this HUD to fire the selector everytime the tableview appears.

Why is it not correct for me to have it occur in the viewWillAppear... is it because that can be loaded so much and I just kept on allocating the object? perhasp I should allocate in viewDidload and fire the

// Show the HUD while the provided method executes in a new thread
        [HUD showWhileExecuting:@selector(loadFilms) onTarget:self withObject:nil animated:YES];

only in my viewWillAppear:?

Thoughts?
A: 

Find all the places where you init/retain/release/autorelease an instance of MBProgressHUD.

The NSZombie tells that this project receives a release message after it is being already deallocated (retain count is zero).

It will help if you will post some code - otherwise it is too difficult to help you...

EDIT:
As you have mentioned in your edit, it would be much better if you'd initiate the HUD only once per view controller (e.g. in viewDidLoad) and call to showWhileExecuting each time you need it (e.g. in viewWillAppear).

But it still doesn't explain the crash.

You you execute the entire code you have posted (as is) for a few times from the same instance of a view controller then you should have memory leaks. That is because I don't see where you release the old instance of HUD.

In addition, you are better set the delegate of the HUD to be nil right before releasing it and before calling the [super dealloc]; in the dealloc method of the view controller.

The last one might cause the EXC BAD ACCESS error.

One more thing, if the entire code you have posted is executed more than once then you should also have few HUD views under the self.view.
I don't know what HUD does in the background - maybe this causes the error...

Michael Kessler
I have edited my answer. See if it helps.
Michael Kessler