Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
pepe_ugalde
Posts: 63
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX
Accepted Solution

App lingers before fully closing

Hello guys

 

I have an app that displays a list and downloads images from the Internet, based on the Image Loader Sample.

 

I open the app and it works as expected, until I close it and on the BB10 home its icon remains semi transparent for 2 or 3 seconds before being opaque again.

 

Also, some times after that, when I open it again, it closes immediately without logging anythng.

 

It started doing it when I added the Image Loader Sample code.

The app uses threads, but I don't think that's the problem, since the Image Loader Sample uses them too and has no issues when closing. The threads quit when the Image Loaders are destroyed.

 

In case it helps, here is everything the Device Log prints from the moment the app is sent to background and then closed (code and message):

0       NavigatorEventHandler::Received - BPS - NAVIGATOR_WINDOW_STATE - NAVIGATOR_WINDOW_THUMBNAIL
0       NavigatorEventHandler::new WindowStateInternal SWIPING
0       LGM - RENDER_BEGIN  SINCE_LAST_RENDER_START: 10394448366 ns
0       LGM - RENDER_END  RENDER_DURATION: 0 ns TOTAL_FRAMES: 70 FRAMES_DROPPED: 14
0       NavigatorEventHandler::Received - BPS - NAVIGATOR_WINDOW_INACTIVE
0       NavigatorEventHandler::new WindowStateInternal PAUSED
0       LGM - RENDER_BEGIN  SINCE_LAST_RENDER_START: 714764518 ns
0       QNXApplicationEngineImpl::Application window not visible, pausing rendering
0       LGM - RENDER_END  RENDER_DURATION: 1000000 ns TOTAL_FRAMES: 71 FRAMES_DROPPED: 15
0       NavigatorEventHandler::Received - BPS - NAVIGATOR_WINDOW_COVER_ENTER
0       NavigatorEventHandler::new WindowStateInternal COVER
0       LGM - RENDER_BEGIN  SINCE_LAST_RENDER_START: 101608182 ns
0       QNXApplicationEngineImpl::Application window is visible, resuming rendering
0       LGM - RENDER_END  RENDER_DURATION: 2000000 ns TOTAL_FRAMES: 72 FRAMES_DROPPED: 16
0       NavigatorEventHandler::Received - BPS - NAVIGATOR_WINDOW_STATE - NAVIGATOR_WINDOW_INVISIBLE
0       NavigatorEventHandler::new WindowStateInternal INVISIBLE
0       LGM - RENDER_BEGIN  SINCE_LAST_RENDER_START: 853836332 ns
0       LGM - RENDER_END  RENDER_DURATION: 0 ns TOTAL_FRAMES: 73 FRAMES_DROPPED: 17
0       LGM - RENDER_BEGIN  SINCE_LAST_RENDER_START: 58109035 ns
0       LGM - RENDER_END  RENDER_DURATION: 0 ns TOTAL_FRAMES: 74 FRAMES_DROPPED: 18
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 528 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 529 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 530 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 531 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 269 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 532 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 533 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 534 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 417 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 158 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 306 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 454 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 195 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 343 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 84 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 491 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 232 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 380 ] not unrealized
9000    ERROR: Context: Object name=" "ImageData" " [objectId= 121 ] not unrealized
0       ClientContext::Destroying server context with 19 remaining objects!
0       ClientContext::Releasing remaining objects...
0       QNXPpsSubscriptionServer::PPS Thread: FINISHED
255     PERFORMANCE_STATISTICS: max frame time: 68 ms, mean render time: 9.61 ms, std.dev render time: 15.17, mean dropped frame time: 40.39 ms, std.dev dropped frame time: 17.10, #rendered frames: 47, #dropped frames: 9
255     BRIDGE_STATISTICS: messages to client: 137, messages to server: 332
255     STARTUP_STATISTICS: started: 501 ms
0       QNXApplicationEngineImpl::Server Thread: FINISHED
0       QNXApplicationEngineImpl::run(EXIT)
9000    BpsEventManagerDependReal::setEventFilter - thread has no event dispatcher 
9000    ApplicationPrivate::resourceManager: ERROR called from non-UI thread QThread(0x10fe90) 
9000    ApplicationPrivate::resourceManager: Method called from non-UI thread

 

Any hints and pointers are appreciated.

 

Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: App lingers before fully closing

You seem to have many objects that you have not cleaned up (all the lines with Object name=" "ImageData").  I would start by elliminating those leaks.

 

You can either clean up the memory yourself or assign a parent object to them that is part of your UI tree (these will be cleaned up when your program ends).  It's hard to say whats best without a code snippet and an idea of what the code is trying to do.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
Regular Contributor
pepe_ugalde
Posts: 63
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX

Re: App lingers before fully closing

[ Edited ]

Thanks for the answer

 

I come from an iOS background, so I know how to create, retain and release objects (and befor that, a little Java), but it seems C++ is different.

 

I don't fully understand pointers, the "new" operator, and how to get rid of unused objects.

Could you please refer me to some memory management tuts? Are there any books or websites you would recommend?

 

A little example:

I declare an ImageTracker and connect its slots and signals. The ImageTracker starts and is asynchronous. How do I make sure that the ImageTracker is deleted and does not leak?

 

void CustomImageLoader::startImgTracker()
{
//-- Start Image Tracker ImageTracker *mImageTracker = new ImageTracker(QUrl("../../data/icons/" + _imageurl)); bool result = connect(mImageTracker, SIGNAL(stateChanged(bb::cascades::ResourceState::Type)), this, SLOT(onTrackerStateChanged(bb::cascades::ResourceState::Type))); Q_ASSERT(result); Q_UNUSED(result);
}

 

 

Regards

Pepe

 

Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: App lingers before fully closing

[ Edited ]

Hi Pepe,

 

A good c++ site that I use is Learn cpp it's aimed at beginner's but I often return to it for reference.

 

Generally the 'new' operator is paired with a 'delete' at the point in which you want to free the memory held.

 

So for your example you need a 'delete mImageTracker;' when you no longer need the object.

 

If your CustomImageLoader class inherits QObject you could also do this:

 

mImageTracker->setParent(this);

 

This will ensure mImageTracker is cleaned up at the point your CustomImageLoader ceases to exist.  In QT parent objects are responsible for cleaning up their children.  Keep in mind that whilst this is convenient, objects maybe kept around for longer than is necessary.

 

Hope I haven't confused you.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
Regular Contributor
pepe_ugalde
Posts: 63
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX

Re: App lingers before fully closing

Thanks! I'll start reading Learn cpp
The setParent tip also seems useful, I'll do some more research on that.

 

Please use plain text.
Regular Contributor
pepe_ugalde
Posts: 63
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX

Re: App lingers before fully closing

Well, I forgot about this thread, but the way I solved it was not logical, a friend with more QML knowledge suggested it and it worked.

 

I had a ListView and a GroupDataModel created in C++ using new and the app set as their parent.

For every item in a JSON I added a new item to the data model, then used delete. I tried setting the app and then the data model as each item's parent, but neither worked, the app kept disabling almost a minute after being closed.

 

What did the trick was setting the GroupDataModel's parent as NULL.

 

*shrug*

Please use plain text.
New Developer
mobilesync
Posts: 11
Registered: ‎09-29-2012
My Device: 9900
My Carrier: *

Re: App lingers before fully closing

Please remark this as the solution. It worked for QListDataModel as well. Thanks a lot.
Please use plain text.
Regular Contributor
pepe_ugalde
Posts: 63
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX

Re: App lingers before fully closing

Glad it worked, also marked as answer.
Please use plain text.