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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
My Carrier: Orange UK

Intermittent error accessing SD card - "Result of expression ... is not a function."

I have an app which logs information to a text file on the phone's SD card.  Because blackberry.io.file.saveFile doesn't allow you to overwirte an existing file, I have to do this:


            blackberry.io.file.rename(dataDirectory + filename, filename + ".bak");
            blackberry.io.file.saveFile(dataDirectory + filename, blob);
            blackberry.io.file.deleteFile(dataDirectory + filename + ".bak");

 

Having encased each of the above in a try/catch, I am finding that intermittently, one of these three statements will fail with an error of the following form:

 

"Result of expression 'blackberry.io.file.saveFile' [file:///SDCard/myapp/logfile.log] is not a function."

 

Clearly there isn't any syntax error in the above code, because it works most of the time.  It isn't even always the same line that fails - I've had each of the three causing the error.

 

The SD card has about 1Gb free, and the file being written is only about 20K.  I know that a USB connection to a PC prevents an app from accessing the SD card, but it's not connected at the time of the error.

 

I've also tried putting a simple loop around the statements, and using a confirm("Retry?") prompt to give the option to retry after a failure.  So far, it has always succeeded on the second attempt.

 

Can anyone give me any ideas on what might be causing this?  Why would my app be unable to access the SD card sometimes, and at others have no problems at all?

 

Retired
Posts: 162
Registered: ‎10-11-2011
My Device: BlackBerry 9810
My Carrier: Rogers

Re: Intermittent error accessing SD card - "Result of expression ... is not a function."

Hi There,

 

I am not sure what is causing the issue that you are experiencing, but here is a fully working sample application, which writes a file to an SD Card.  Try this sample application on your device and see if the same issue occurs.

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/BlackBerry-WebWorks-Sample-Code-...

 

Thanks

 

Naveen M

Contributor
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
My Carrier: Orange UK

Re: Intermittent error accessing SD card - "Result of expression ... is not a function."

Thanks.  I haven't been able to reproduce the same error since posting this.  However, I have produced another one which may be related..

 

Since the error I reported here is intermittent, I figured the best chance of reproducing it was to use the same code as in your sample app, but to add a loop so as to make the application save the file repeatedly.  I changed the saveFile() function to remove the alerts, so that it would repeat without interruption.  Then I added a new menu option which calls the following function:

 

var timer;
var i = 0;
function repeatSave() {
    i += 1;
    document.getElementById("taContents").innerHTML = "Saving count: " + i;
    saveFile();
    timer = setTimeout("repeatSave()", 500);
}

 

As you can see this simply calls the saveFile() function every 500 milliseconds.  I then let it run for a few hours, and when I checked on it I found that the memory being used by the application was in excess of 19Mb.  There is clearly a memory leak here.  See screenshot below.

 

Screenshot

 

I emphasise that apart from the changes mentioned above I have not changed your sample app at all in order to produce this problem.

 

This is consistent with an identical problem I had with another app - except that the memory leak was much more dramatic, going up to 90+ Mb in a few hours.  The difference there was that the app was much more complex and file being saved was much larger - up to 512K.

 

Please advise.

 

Thanks.

 

Contributor
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
My Carrier: Orange UK

Catastrophic memory leak using File IO repeatedly

[ Edited ]

Bump.  Any comments from RIM please?  Or is this kind of memory leak the sort of thing we're supposed to expect with Webworks?

 

Mike

 

 

PS How do I edit the title of this thread to more accurately reflect the problem?

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Catastrophic memory leak using File IO repeatedly

There have been memory leaks with WebWorks in the past but they have made progress on removing them in the later versions of the SDK. Which WebWorks SDK version are you building the application with? The latest one is always the recommended one for this reason.

Tim Windsor
Open Source Technical Lead
Contributor
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
My Carrier: Orange UK

Re: Catastrophic memory leak using File IO repeatedly

BlackBerry WebWorks SDK 2.3.1.5

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Catastrophic memory leak using File IO repeatedly

Okay. The other thing to see is if the Garbage Collector runs and cleans it up or if the memory stays allocated. If you let your device sit for a while and check the memory again, if it's better then we know that there is memory used by the system to save but it's not leaking. If it's still low then there's definitely a leak.

Tim Windsor
Open Source Technical Lead
Contributor
Posts: 35
Registered: ‎12-28-2010
My Device: Bold 9780
My Carrier: Orange UK

Re: Catastrophic memory leak using File IO repeatedly

Thanks for your reply - the thing is, it takes several hours for the memory to go up like this - the last time I tested it, it was sitting on my bedside table all night, and in the morning I took the snapshot above.  So I think the Garbage Collector had plenty of time to do its thing.

 

I guess it's probably not the sort of thing that you'd notice in normal testing, because it appears to take thousands of repeated saveFile operations before the leak is substantial enough to notice.  I only noticed it because I was working on an app which is intended to run in the background constantly, and logs information in a text file every minute or so.  In that case it took a few days and got to 90Mb, at which point the phone was pretty much dead!  Then I tested it using the File IO sample application, as described above, and was able to reproduce the problem very easily over the space of a few hours.