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
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

<bb/cascades/WebView> leaks memory

WebView appears to leaks significant amounts of memory. Does anybody have a solution to this?

If you push a page with WebView in it onto a NavigationPane stack that WebView memory is never freed from the heap (despite the page being deleted when pop is called).

 

Here's an example that's just a navigation page with two buttons to push two different webviews:

https://github.com/BrennanR/WebViewTest

Notably once a page has been pushed once, pushing the same page again doesn't seem to take up any more memory, so the webview must be finding the page data in a cache somewhere (apparently stored entirely on the heap -_-)

 

In any case, it's very simple to crash an application by just opening up WebViews with different URLs.

 

Is this a known bug? Does this work as poorly on a device? I don't have a device so I'm only testing on the emulator.

 

Here's some screenshots of running the application and demonstrating the stack more or less only goes up (a trivial amount of memory is sometimes freed).

 

FirstPage.png

After pushing the first page.

 

 

 

SecondPage.png

After popping the first page then pushing the second page.

 

 

HomeScreen.png

After pushing and popping both pages, and back to the root navigation window.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Highlighted
Contributor
Posts: 20
Registered: ‎02-21-2012
My Device: Bold 9900
My Carrier: AT&T

Re: <bb/cascades/WebView> leaks memory

[ Edited ]

I couldn't crash it.

 

But...

 

Take a look at this:

 

// Navigation pane project template
import bb.cascades 1.0

NavigationPane {
    id: navigationPane
    
    property Page pushedPage
    
    Page {
        // page with a picture thumbnail
        Container {
            background: Color.Black
            layout: StackLayout {
            }
            Button {                
                text: qsTr("Show detail")
                imageSource: "asset:///images/picture1thumb.png"
                onClicked: {
                    // show detail page when the button is clicked
                    var page = getSecondPage();
                    console.debug("pushing detail " + page)
                    navigationPane.push(page);
                }
                // Removing this.
                //property Page secondPage
                function getSecondPage() {
                    if (! pushedPage) {
                        pushedPage = secondPageDefinition.createObject();
                    }
                    return pushedPage;
                }
                attachedObjects: [
                    ComponentDefinition {
                        id: secondPageDefinition
                        source: "DetailsPage.qml"
                    }
                ]
            }
            
            Button {                
                text: qsTr("Show detail")
                imageSource: "asset:///images/picture1thumb.png"
                onClicked: {
                    // show detail page when the button is clicked
                    var page = getThirdPage();
                    console.debug("pushing detail " + page)
                    navigationPane.push(page);
                }
                // Removing this
                // property Page thirdPage
                function getThirdPage() {
                    if (! pushedPage) {
                        pushedPage = thirdPageDefinition.createObject();
                    }
                    return pushedPage;
                }
                attachedObjects: [
                    ComponentDefinition {
                        id: thirdPageDefinition
                        source: "DetailsPage1.qml"
                    }
                ]
            }
        }
    }
    onCreationCompleted: {
        // this slot is called when declarative scene is created
        // write post creation initialization here
        console.log("NavigationPane - onCreationCompleted()");

        // enable layout to adapt to the device rotation
        // don't forget to enable screen rotation in bar-bescriptor.xml (Application->Orientation->Auto-orient)
        OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
    }
    
    // Taken directly from Quotes
    onPopTransitionEnded: {
        if(pushedPage == page) {
            page.destroy();
        }
    }
}

 

Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: <bb/cascades/WebView> leaks memory

[ Edited ]

Correct, it won't actually crash with only those two URLs, I tried to demonstrate the problem with as little code as possible. In reality I have a massive project that can push an effectively infinite amount of different URLs in WebViews as new Pages on the navigation stack. If a couple of those webpages end up being large, the application will eventually bog down and leak enough memory to crash.

 

Unfortunately adding that code (your changs) has little effect to heap usage (this is after pushing and popping both pages):

changes.png

 

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Contributor
Posts: 20
Registered: ‎02-21-2012
My Device: Bold 9900
My Carrier: AT&T

Re: <bb/cascades/WebView> leaks memory

I wouldn't worry too much because my app uses just a few more panes and uses the code recommended by the examples, and it has crashed a few times. 

 

I'm certain it's the emulator. They aren't perfect. Heck, Radiant Defense doesn't even open. Are we to say that it's broken? Nope!