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
Developer
ondrejandrej
Posts: 81
Registered: ‎03-17-2013
My Device: Dev Alpha + Z10
Accepted Solution

ControlDelegate does not clean up objects after itself

 

In order to avoid slowing down the app startup, I create a Login Dialog dynamically only if the user hasn't signed in earlier. I have the following code attached to main Page:

    attachedObjects: [
        ControlDelegate {
            id: loginDialogDelegate
            delegateActive: false
            sourceComponent: loginDialogDef
        },
        ComponentDefinition { 
            id: loginDialogDef
	        LoginDialog {
	            id: loginDialog
	            onCreationCompleted: {
                	open() 
                }
	            onClosed: {
                    loginDialogDelegate.delegateActive = false 
                }
	        }
	    }
    ]

The code of the dialog is in LoginDialog.qml. In the main page I set loginDialogDelegate.delegateActive to true when I need to show the dialog. However, when I close the app, I get lots of "ERROR: Context: Object name=" "Label" " [objectId= 103 ] not unrealized".

 

I was expecting that setting ControlDelegate.delegateActive to false cleans up the instance of LoginDialog. It seems that I'm wrong. How do I modify the code to do so?

I already tried to set delegateActive to false explicitly (not only in the slot), but it also doesn't work.

 


SQL Terminal – command-line interface to local SQLite database
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: ControlDelegate does not clean up objects after itself

Hi ,

 

You are actually right. The ControlDelegate instance gets deleted when the delegateActive flag is set to false (API docs).

 

I suggest you try moving the definition of the ControlDelegate object to the main container and not as an attached object. Also, you might want double-check that the onClosed slot of the LoginDialog object is indeed entered (through console logging).

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
ondrejandrej
Posts: 81
Registered: ‎03-17-2013
My Device: Dev Alpha + Z10

Re: ControlDelegate does not clean up objects after itself

[ Edited ]

 

I moved ControlDelegate instance to the main container. The result is the same. I also tried to remove ControlDelegate and create ComponentDefinition instance with createObject() (see ComponentDefinition page). That also works, login dialog is shown, but when the app is terminated I get the same errors as mentioned in the first post.

 

I verified the execution of onClosed handler and also set loginDialogDelegate.delegateActive to false elsewhere in the code.


SQL Terminal – command-line interface to local SQLite database
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: ControlDelegate does not clean up objects after itself

Can you share the entire section of the relevant code? With the code provided here, it is not possible to reproduce what you are seeing.

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
ondrejandrej
Posts: 81
Registered: ‎03-17-2013
My Device: Dev Alpha + Z10

Re: ControlDelegate does not clean up objects after itself

Here is the entire main.qml:

import bb.cascades 1.2
import "Login"

TabbedPane {
    id: root
    property bool signedIn: false
    onCreationCompleted: {
       // loginDialogDelegate.delegateActive = true
    }
	showTabsOnActionBar: false
	Tab {
		title: qsTr("My Trips") + Retranslate.onLanguageChanged
		imageSource: "asset:///images/icon_home.png"
		
		// Default delegateActivationPolicy explicilty stated for clarity only, the delegates object 
		// (the ContinentsPage) will be created/destroyed when the tab is selected/unselected.
		delegateActivationPolicy: TabDelegateActivationPolicy.Default
		
		MyTripsPage {
		    signedIn: root.signedIn
		    onSignInTriggered: {
		        loginDialogDelegate.delegateActive = true
          	}
   		}
	} 
	Tab {
	   // enabled: false
		title: qsTr("Itinerary") + Retranslate.onLanguageChanged
		imageSource: "asset:///images/icon_favorites.png"
		
		delegate: Delegate {
			source: "ItineraryPage.qml"
		}
	}
    attachedObjects: [
        ControlDelegate {
            id: loginDialogDelegate
            delegateActive: false
            sourceComponent: loginDialogDef
        },
        ComponentDefinition { 
            id: loginDialogDef
	        LoginDialog {
	            onCreationCompleted: {
                	open() 
                }
	            onClosed: {
                  	loginDialogDelegate.delegateActive = false 
                }
	            onSignInSuccess: {
	            	root.signedIn = true 
	            }
	        }
	    } 
    ]
}

 In order to run the example, you need LoginDialog.qml etc. However I'm afraid I can't post the entire source of our app here.


SQL Terminal – command-line interface to local SQLite database
Developer
ondrejandrej
Posts: 81
Registered: ‎03-17-2013
My Device: Dev Alpha + Z10

Re: ControlDelegate does not clean up objects after itself

 

I don't know whether it's related to this problem, but I create a WebView instance in my C++ code on the heap. It is not visible in the app.

	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	wView = new WebView();
	wView->setUrl(QUrl("local:///assets/index.html"));
	wView->reload();

	AbstractPane *root = qml->createRootObject<AbstractPane>();
	wView->setParent(root);

	app->setScene(root);

 it causes the following error:

ERROR: Context: Object name=" "ForeignWindow" " [objectId= 12 ] not unrealized

Before I added the line with setParent() I also got this error for WebView instance.


SQL Terminal – command-line interface to local SQLite database
Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: ControlDelegate does not clean up objects after itself

Please create a simple test project reproducing the issue.
Most likely there is a bug somewhere in the application, but it's impossible to debug it remotely. :smileyhappy:

WebView is an unrelated issue. createRootObject creates a TabbedPane (TabbedPane is top-level element in QML file above). Then WebView is created in code and it's parent property is set to tabbed pane.

But I don't see where the WebView is added to views hierarchy. Parent-child relationship is an object lifetime management mechanism. You still have to add the object to a container, it's not done automatically. Also, it's not possible to add WebView directly to TabbedPane, there should be a tab with a page.

Andrey Fidrya, @zmeyc on twitter
Developer
ondrejandrej
Posts: 81
Registered: ‎03-17-2013
My Device: Dev Alpha + Z10

Re: ControlDelegate does not clean up objects after itself

 

Thanks. I will create the test project later.

 

As I mentioned, the WebView instance is not intended to be visible in the app. Instead, it's only used to run some Javascript code in the html file.

 

 


SQL Terminal – command-line interface to local SQLite database
Developer
greenmr
Posts: 919
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: ControlDelegate does not clean up objects after itself

Actually there are LOTS of cascades visual objects that don't clean up after themselves properly. I logged a bug with share invocation where the share page that pops up doesn't clean up any of it's buttons and the like. Unfortunately there has been no resolution to that bug so far. It seems that the Cascades development team is a little lax about making sure that every contained object has a parent.

 

:No:



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Developer
greenmr
Posts: 919
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: ControlDelegate does not clean up objects after itself

Yep, this bug has been around forever, and the general consensus on this board is basically, ignore it, since it doesn't actually cause any problems for the user, and the BB10 memory manager force cleans anything like this when the app is closed.

 

Still, it is sloppy, and has been around a very long time, so it should have been fixed by now.

 


ondrejandrej wrote:

 

I don't know whether it's related to this problem, but I create a WebView instance in my C++ code on the heap. It is not visible in the app.

	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	wView = new WebView();
	wView->setUrl(QUrl("local:///assets/index.html"));
	wView->reload();

	AbstractPane *root = qml->createRootObject<AbstractPane>();
	wView->setParent(root);

	app->setScene(root);

 it causes the following error:

ERROR: Context: Object name=" "ForeignWindow" " [objectId= 12 ] not unrealized

Before I added the line with setParent() I also got this error for WebView instance.






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.