Log in or register to post comments

Memory Leak with Vuforia iOS

March 10, 2014 - 10:08am #1

Hello,

 
I have a ~20Mb memory leak in my iOS project coming every time we initialising the Vuforia framework.
 
The VideoPlayback demo from Vuforia's demo code suite can be used to demonstrate this memory leak:
1/ Launching the app
2/ Pressing the "start" button to init Vuforia and start the AR activity
3/ Opening the menu and pressing the "about" button to deinit Vuforia and stop the AR activity.
4/ Go back to 2/
5/ The xcode 5 memory figure will look like the png attached.

 

Please notice that I can't keep Vuforia alive in my project, it needs to be load/unload.
 
Any help on this issue?
 
Thank you
AttachmentSize
Image icon vuforia.png31 KB

Memory Leak with Vuforia iOS

March 13, 2014 - 7:06am #7

A quick check should be to put a bp in the dealloc of your ViewController to make sure that it is actually called. Make sure also that the destroyDatSet is also actually called.

 

Good luck with your development!

Memory Leak with Vuforia iOS

March 13, 2014 - 4:20am #6

Hello and thank you for your answer.

Applying theses changes reduced my leak from ~20Mb to ~1Mb, that I fixed by setting a weak reference to the ViewController inside the EAGLView class.

 

Thanks for your help.

Memory Leak with Vuforia iOS

March 11, 2014 - 9:24am #5

Hi Andrew,

There are knows memory leaks in the sample apps and they will be fixed in the next release.

In the meantime, you should not use the Menu classes, which are in the SampleAppUI directory : as those classes are specific to the sample app here, I suppose you are not using them in your own application right? If you really need to use those, I can provide the details about how to fix those.

There are 3 changes you may want to do in your own classes though if you are following the same pattern as our sample apps:

The code for the notification should be:

.../..
   // we use the iOS notification to pause/resume the AR when the application goes (or come back from) background

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(pauseAR)
     name:UIApplicationWillResignActiveNotification
     object:nil];

   
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(resumeAR)
     name:UIApplicationDidBecomeActiveNotification
     object:nil];
}

- (void) pauseAR {
    NSError * error = nil;

    if (![vapp pauseAR:&error]) {
        NSLog(@"Error pausing AR:%@", [error description]);
    }
}

- (void) resumeAR {
    NSError * error = nil;

    if(! [vapp resumeAR:&error]) {
        NSLog(@"Error resuming AR:%@", [error description]);
    }
    // on resume, we reset the flash and the associated menu item
    QCAR::CameraDevice::getInstance().setFlashTorchMode(false);
    SampleAppMenu * menu = [SampleAppMenu instance];
    [menu setSelectionValueForCommand:C_FLASH value:false];
}

 

Don't forget to remove those observers in the dealloc:

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
  • In the SampleApplicationSession.m, the delegate is a retain property, it should be assign:
@property (nonatomic, assign) id delegate;
  • Finally, in the doUnloadTrackersData method of your controller, you need to destrot yhe dataset, once it has been deacrivated:
// unload the data associated to your trackers
- (bool) doUnloadTrackersData {
    if (dataSet != NULL) {
        // Get the image tracker:
        QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
        QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(trackerManager.getTracker(QCAR::ImageTracker::getClassType()));
        
        if (imageTracker == NULL)
        {
            NSLog(@"Failed to unload tracking data set because the ImageTracker has not been initialized.");
            return false;
        }
        // Deactivate the data set:
        if (!imageTracker->deactivateDataSet(dataSet))
        {
            NSLog(@"Failed to deactivate data set.");
            return false;
        }
        if (!imageTracker->destroyDataSet(dataSet))
        {
            NSLog(@"Failed to destroy data set.");
            return false;
        }
        dataSet = NULL;
    }
    return true;
}

 

Tell me if that works for you!

 

Pierre

Memory Leak with Vuforia iOS

March 11, 2014 - 3:33am #4

AlessandroB wrote:

There is a memory leak in the VideoPlayback iOS sample ... which is cused by the UI framework used in the sample (which is not part of the Vuforia SDK)

Could you tell us which part of the UI framework causes the leak?  This would help us identify and fix the problem.  Thanks!

Memory Leak with Vuforia iOS

March 11, 2014 - 1:54am #3

[... ]extract the core part of the VideoPlyback sample and build your own App without the UI logic of the original sample.

Do you mind elaborating a bit about where exactly the faulty code is? I did exactly that, I used the Core of the VideoPlayback sample as a starting point for creating my own app but I experience these leaks as well. Basically what I did was removing all ViewControllers in the SampleAppUI Subfolder in Xcode and creating my own ViewControllers for the NavigationController. 

 

 

Memory Leak with Vuforia iOS

March 10, 2014 - 12:10pm #2

There is a memory leak in the VideoPlayback iOS sample, which will be fixed in the next release of Vuforia and the samples; this is a sample code level issue which is cused by the UI framework used in the sample (which is not part of the Vuforia SDK), so, my suggestion is to extract the core part of the VideoPlyback sample and build your own App without the UI logic of the original sample. 

 

Log in or register to post comments