Monday, December 20, 2010

Blackberry General Socket Exception and TCP sockets

Switching gears for a minute to the hell that is Blackberry development.
The situation is this.
I need to perform a TCP socket communication from a Blackberry Bold 9700 to a socket on a server that I have set up to listen for the requests. I won't go in to how to do that, there's plenty of documentation elsewhere. The problem is this: My app makes these socket calls very quickly, and consistently at 31 calls to the socket client my app fails with a "General Socket Exception." My app is then in a state where I have two choices. Shut down the device and restart, or let it sit for several minutes before attempting to make the socket call again. Neither option is acceptable. I've made attempts to ensure that my objects are closed and set to null. I've made every effort to ensure I don't have any leaks in my socket client.
There are alot of people running in to this, but nobody giving any real resolution. After fighting with this for a while, I've resolved my problem. Maybe it will help you with yours. As it turns out, my calls are happening too quickly for the Blackberry garbage collection to take out the trash. I'm using up my resources, and failing future calls. In order to get around this I've made use of the System.gc() method. Clean, simple, and the only solution that I've found that works. It cleans up the resources before I have a chance to use em all up, and allows my app to continue making the calls without issues.

Edit 10/7/2011
So, it's been forever, and the answer is above, but I thought I'd follow up. After getting with Blackberry engineers, asking for help, the only response I got was documentation on how to find memory leaks. Not helpful, I know where the leak is, I just don't know what to do about it. What ever, it appears that my test was much higher stress than actual production use. We have yet to encounter the issue in production use, and in fact, have had to make other adjustments that will slow the app even further. 

No comments:

Post a Comment