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

Web and WebWorks Development

Reply
Regular Contributor
Saeger
Posts: 83
Registered: ‎04-29-2011
My Device: 9300 Curve

Re: Device memory is Low issue for an WebWork app

So, Tim,

 

In this case, we'll have to just "re-write" our javascript extensions using the new framework ?

This affects the phonegap? Because my applications are based on phonegap framework too, and re-write some phonegap code it's not an options for my company.

Márcio Saeger - Software Engineer, Softwell Solutions
Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Device memory is Low issue for an WebWork app

We'll be working with Nitobi for any possible chages to PhoneGap to ensure that it's running great!

 

We'll also be publishing information on how to either "augment/fix" your existing extension to ensure that it doesn't have any problems as well as publishing how to build extensions in the new framework.

 

The only extensions that we have seen that exhibit this behaviour are those that hold onto an instance of the BrowserField2 object as a member variable.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
joygupta
Posts: 31
Registered: ‎05-06-2011
My Device: 9300

Re: Device memory is Low issue for an WebWork app

Hi,

I too am facing the same problem while loading multiple pages. do you got any solution of the problem. Please let me know, I am stuck in this.

 

Thanks in advance.

Joy

Please use plain text.
New Member
atrevers
Posts: 4
Registered: ‎07-28-2011
My Device: Torch 9800

Re: Device memory is Low issue for an WebWork app

Hi Tim

 

Can you confirm when the fix to WebWorks is likely to be released? Also, presumably once it is released then all we need to do to take advantage of the fix is to recompile using the latest version of the packager tool?

 

Many thanks,

 

Andrew

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Device memory is Low issue for an WebWork app

Hi Everyone,

 

We have gotten to the bottom of the Memory Drain.  Basically there is a scenario where garbage collection is "supposed" to be happening but isn't.

 

The issue is surrounding JavaScript extensions.  Extensions are written using Java ScriptableObjects that are then injected into the JavaScript engine.  It appears that if the ScriptableObject has any kind of handle to an object that is part of the application container it will never get garbage collected.  What is happening seems to defy the rules of garbage collection, but it is in fact happening.

 

What the culprit seems to be is if you have a member variable in the ScriptableObject that has a handle to something in the application framework such as a member variable storing a reference to the BrowserField or a Java Screen object it increases the reference count on that pointer and thus the ScriptableObject never gets released.

 

The solution that we found to this, is that if you need to pass in objects such as BrowserField or the screen or other things into a ScriptableObject, you must maintain their reference using a WeakReference object.  This will not increase the reference count on the object and therefore garbage collection will clean it up.

 

We use Scriptable objects as part of the framework around accessing caching information or focus based navigation mode as well as all the other APIs.  As soon as you turn on caching or focus based navigation it will use some Scriptable objects that have this issue.  There are other APIs that also have this issue.

 

We are currently working on getting these resolved and hope to have them fixed in the next release of the Smartphone SDK due out in a couple of weeks.  All you will have to do is re-compile your WebWorks application

 

For those writing their own JavaScript extensions you can see below what the old way looked like and what the new way looks like.

 

Old Way Pseudo Code


public MyNamespace( BrowserField bf) {
  _bf = bf;

  // Do my stuff
}

 

New Way Pseudo Code

 

public MyNamespace( BrowserField bf ) {
  _bfWeakReference = new WeakReference( bf );

  // Do stuff
}

private BrowserField getBrowserField() {
  Object o = _wbfWeakReference.get();
  if ( o instanceof BrowserField ) {
    return (BrowserField)o;
  } else {
    return null;
  }
}
Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Regular Contributor
Saeger
Posts: 83
Registered: ‎04-29-2011
My Device: 9300 Curve

Re: Device memory is Low issue for an WebWork app

[ Edited ]

So Tim, in case of phonegap extensions, i'll have to do that with the phonegap framework, since phonegap extensions doesn't work with BrowserFields and ScriptableObject's... Right?
There's some way that your team could help us with that?

 

 

Edit: I just found 2 classes that references to BrowserField (phonegap 0.9.4): "PhoneGapExtension" and "HttpUtils".

 

PhoneGapExtension.java:

 

    public void register(WidgetConfig widgetConfig, BrowserField browserField) {
        browser = browserField;

        // grab widget application name and use it to generate a unique ID
        appName = widgetConfig.getName();
        appID = Long.parseLong(Math.abs(("com.phonegap."+appName).hashCode())+"",16);
        
        // create a notification profile for the application
        Notification.registerProfile();
    }

	public static BrowserField getBrowserField() {
	    return browser;
    }

 

HttpUtils (References the method of PhoneGapExtension):

 

    public static String getCookie(String url)
    {
        return PhoneGapExtension.getBrowserField().getCookieManager().getCookie(url);
    }

 

Márcio Saeger - Software Engineer, Softwell Solutions
Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Device memory is Low issue for an WebWork app

PhoneGap does use ScriptableObjects... We haven't audited their code yet to see if they have any of these instances.  There is a specific case that causes the memory drain.  Not all ScriptableObjects have the problem.

 

We will be working with Nitobi to correct any issues that are in PhoneGap.. if any.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Device memory is Low issue for an WebWork app


Saeger wrote:

So Tim, in case of phonegap extensions, i'll have to do that with the phonegap framework, since phonegap extensions doesn't work with BrowserFields and ScriptableObject's... Right?
There's some way that your team could help us with that?

 

 

Edit: I just found 2 classes that references to BrowserField (phonegap 0.9.4): "PhoneGapExtension" and "HttpUtils".

 

PhoneGapExtension.java:

 

    public void register(WidgetConfig widgetConfig, BrowserField browserField) {
        browser = browserField;

        // grab widget application name and use it to generate a unique ID
        appName = widgetConfig.getName();
        appID = Long.parseLong(Math.abs(("com.phonegap."+appName).hashCode())+"",16);
        
        // create a notification profile for the application
        Notification.registerProfile();
    }

	public static BrowserField getBrowserField() {
	    return browser;
    }

 

HttpUtils (References the method of PhoneGapExtension):

 

    public static String getCookie(String url)
    {
        return PhoneGapExtension.getBrowserField().getCookieManager().getCookie(url);
    }

 


Can you post up the URL in github that points to the API?

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Regular Contributor
Saeger
Posts: 83
Registered: ‎04-29-2011
My Device: 9300 Curve

Re: Device memory is Low issue for an WebWork app

[ Edited ]

You mean:
https://github.com/phonegap

bb:

https://github.com/phonegap/phonegap-blackberry-webworks

 

Márcio Saeger - Software Engineer, Softwell Solutions
Please use plain text.
Regular Contributor
Saeger
Posts: 83
Registered: ‎04-29-2011
My Device: 9300 Curve

Re: Device memory is Low issue for an WebWork app

[ Edited ]

Tim,

 

According to your way, i made this:

 

Class PhoneGapExtension.java

Replace this:

 

protected static BrowserField browser = null;

 For this:

protected static WeakReference _bfWeakReference = null;

 

Replace this:

 

    public void register(WidgetConfig widgetConfig, BrowserField browserField) {
    	browser = browserField;

        // grab widget application name and use it to generate a unique ID
        appName = widgetConfig.getName();
        appID = Long.parseLong(Math.abs(("com.phonegap."+appName).hashCode())+"",16);
        
        // create a notification profile for the application
        Notification.registerProfile();
    }

 

For this:

    public void register(WidgetConfig widgetConfig, BrowserField browserField) {
    	_bfWeakReference = new WeakReference(browserField);

        // grab widget application name and use it to generate a unique ID
        appName = widgetConfig.getName();
        appID = Long.parseLong(Math.abs(("com.phonegap."+appName).hashCode())+"",16);
        
        // create a notification profile for the application
        Notification.registerProfile();
    }

 

And finally this:

 

	public static BrowserField getBrowserField() {
		return browser;
    }

 

for this:

 

	public static BrowserField getBrowserField() {
		Object o = _bfWeakReference.get();
		if(o instanceof BrowserField) {
			return (BrowserField)o;
		}else {
			return null;
		}
    }

 

 

I'll test it right now and come back with results

Márcio Saeger - Software Engineer, Softwell Solutions
Please use plain text.