Any techniques to stop app from running slow?

netchicken

Active Member
Licensed User
Longtime User
My app starts to run slow after a while and the scroll view staggers.

If I turn it off and start it again it runs back like normal. but considering I am using a Samsung Galaxy S2 its a pretty concerning issue.

I am making a simpler interface using a listview instead of the scroll view, but thats really a 2nd rate solution.

Are there any techniques / code to free up resources, or whatever for your app so it doesn't do this?

For example i am using cursor1.close after each call on the DB.


Here is the app

http://www.b4x.com/forum/basic4android-share-your-creations/11909-shopping-list-program.html
 
Last edited:

netchicken

Active Member
Licensed User
Longtime User
Darn. I only have 2 bmps. However changing the values in the progress bars, which happens when I click on the bmps, and they swap, does seem to slow it down.

Is it just that scrollview doesn't work well with about 20 - 30 entries?

PS: sorry for putting this in the wrong forum.
 
Upvote 0

Helihead

Member
Licensed User
Longtime User
Program slows down over time and becomes practically unusable

I know this is an old thread but seemed the best place to continue this issue...

I have been using Basic4PPC now for 2 or 3 years and really love it but I have been coding for about 35 years so I know a problem when I see one. I am hesitant to release an application I have been working on because applications I develop in Basic4PPC progressively slow down over time. No not the one or two screen one with no DB access and limited features but anything I code with DB access, listviews and multiple screens seems to have this issue to some extent.

Code has been done on one specific app for over a year and I have been troubleshooting this issue since then with no luck.

- Run the app and use the features and you can see the listViews get slower and slower.

- Run the app and let it sit for a while (15 or 30 minutes) and you can see the listviews slow way down even first time you access one of them

- Run the app and let it sit open for an hour untouched and the list views won't even scroll

- Close the app and reopen and everything is fast again for a while

We have seen this exact behavious on 5 different tablets and 4 different phones

No other apps do it on my phone, only the ones I have written in Basic4PPC.

My app is about 10000 lines of code, fairly heavy DB access, 29 screen layouts with 9 variants each.

I have researched here and this thread describes the issue I initially thought I had until I noticed that it slows down even if you do not actively exercise the app, just leave it open and it slows down.

I eliminated all bitmaps and tested, eliminated the DB routines and tested with dummied data, tried everything I can think of to cleanup up possible memory issues after setting up DB, listview and other potentially memory hog controls. Nothings seems to work.

I have read responses on here for nearly 3 years so I know the next statement is that you can't possibly help without seeing my code. I have been an engineer long enough to know that there are things that you should be able to recommend without seeing my code.

- Where are the potential memory leaks?

- Are the listViews likely to progressively slow the app down even if you don't access them?

- Is there a way to programmatically clear the program memory without a restart?

- Is there anything special I should do to clean up DB cursors and the like after using them?

The listViews in particular are suspect. Mine are either one line with icons or two lines with icons and the code is pretty much copy and paste frpm the examples here with slight name changes to support my app.

At this point, I'm trying to decide if I have wasted 2 years coding and debugging as it is too big an issue to ever release the app with this problem. Like I said, 5 different tablets and 4 phone and only Basic4PPC apps do it.

I can't be the only one to ever see this.

The developers of this otherwise awesome development environment have to have some ideas what to troubleshoot without seeing my app. If you want to see certain lines of code, I can probably pull those out and send.

Suggestions before I ditch all this work and Basic4ppc for good?

Thanks
Jeff
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are you asking about Basic4android or Basic4ppc?
Edit: seems like you are asking about Basic4android.

There is nothing inherent in Basic4android that will cause your app to slow down over time. It is really hard to say without seeing your code. Loading many bitmaps (especially without using LoadBitmapSample) can cause memory issues.

Incorrectly working with SQL objects can also cause problems. Can you upload your project?
 
Upvote 0

Helihead

Member
Licensed User
Longtime User
Sorry yes for Android. I was looking at the Basicfor PPC page right before I posted this.

Basic4Android.

I only have 1 bitmap on each of 3 of the 29 screens and they are all 100x100 so not large. I have remmed out all the bitmap code and just left text placeholders for them and still get the same behaviour so I do not believe it has anything to do with the bitmaps.

I have no timers running and the only sensor with a change event is for the orientation sensor and I only initialize and start listening on a certain page that seldom gets used. When I leave that page I stop listening.

What else would Basic4Android have running in the background that would be consuming memory even if the user is not hitting buttons, moving listviews, etc.?

Your statement "Incorrectly working with SQL objects can also cause problems." intrigues me.

I can't upload all my app code but below is typical of how I pull of push data to/from the DB. Loads data from the DB and sticks it in a listView called :

Dim listFields As ListView ' Declared up in Globals section

'further down in code
Dim num As Int
loadScreen("fields") ' Designer Screen containing listFields
listFields.FastScrollEnabled = True ' Tried with and without this

num = sqlCon.ExecQuerySingleResult("SELECT count(*) FROM fields")
Cursor = sqlCon.ExecQuery("SELECT DISTINCT field, state FROM Fields ORDER BY field, state ASC")

listFields.clear
If num = 0 Then
listFields.AddSingleLine("No fields in fields table!")
Else
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
Try
listFields.AddSingleLine(Cursor.GetString("field").Trim & " - " & Cursor.GetString("state").Trim)
Catch
' Handle error
End Try
Next
End If
Try
Cursor.Close
Catch
End Try

I suspected these were leaving memory hanging but have tried to clear several different ways.

Thanks for your help



Are you asking about Basic4android or Basic4ppc?
Edit: seems like you are asking about Basic4android.

There is nothing inherent in Basic4android that will cause your app to slow down over time. It is really hard to say without seeing your code. Loading many bitmaps (especially without using LoadBitmapSample) can cause memory issues.

Incorrectly working with SQL objects can also cause problems. Can you upload your project?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is more or less impossible to say without seeing your code. I forgot to write in my previous post that the UI Cloud is an example of long running app written with Basic4android. The devices are running for months without any performance degradation.

Things you should check:
- Make sure that there are no warnings (assuming that you are using v2.7).
- Make sure that the SQL objects are process_global variables and are only initialized once when FirstTime is True.
- Same thing for the sensor. The sensor is a major suspect here.
 
Upvote 0

Helihead

Member
Licensed User
Longtime User
Not completely consistent here but I will go fix - ":- Make sure that the SQL objects are process_global variables and are only initialized once when FirstTime is True."

Yes I do this already - " - Same thing for the sensor. The sensor is a major suspect here."
 
Upvote 0

Helihead

Member
Licensed User
Longtime User
Running the strictmode library on the code below results in a warning that I am not closing the cursor or database object. I'm calling the cursor close and even removed it from the Try loop and confirmed that it does execute correctly.

Why am I getting an error saying it's not closed after I call cursor.close.

I also tried adding

"If sqlCon.IsInitialized = False Then
sqlCon.Initialize(File.DirDefaultExternal, "rockdat.sal", False)
End If"

before the first sql call and

"If sqlCon.IsInitialized = True Then
sqlCon.Close
End If"

After the Cursor.close and I get the same message.


Dim listFields As ListView ' Declared up in Globals section

'further down in code
Dim num As Int
loadScreen("fields") ' Designer Screen containing listFields
listFields.FastScrollEnabled = True ' Tried with and without this

num = sqlCon.ExecQuerySingleResult("SELECT count(*) FROM fields")
Cursor = sqlCon.ExecQuery("SELECT DISTINCT field, state FROM Fields ORDER BY field, state ASC")

listFields.clear
If num = 0 Then
listFields.AddSingleLine("No fields in fields table!")
Else
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
Try
listFields.AddSingleLine(Cursor.GetString("field").Trim & " - " & Cursor.GetString("state").Trim)
Catch
' Handle error
End Try
Next
End If
Try
Cursor.Close
Catch
End Try
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Want to make your program run slow (like I did - not meaning too)?

Just stick a "DoEvents" inside the loop that fetches images for a scroll list.

It went from "blink" to watch each item paint before fetching the next... very slow...



B4X:
Sub GetThisImg(Buf() As Byte) As Bitmap
 
   Dim InputStream1 As InputStream
      ' DoEvents
   If Buf.Length > 0 Then
      InputStream1.InitializeFromBytesArray(Buf, 0, Buf.Length)
      Dim BM As Bitmap
      BM.Initialize2(InputStream1)
      InputStream1.Close
   End If 
   Return BM
 
End Sub
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I've got an App that has ListViews and SQLite DB access..

This seems to be fine when accessing data.

In terms of the database :

How many rows are we talking about?

How many columns does the table or tables have?

Have you looked at indexes?

Are you only reading data or are you updating or deleting or creating data?

I use the Firefox SQLite add-on and manage my databases in that, it gives me more tools and I can access all the information about the databases, but realistically I only ever read the data from them. Although creates/deletes happen on a separate table which then relates to the main, driving table.. So they just reference the code.

Have you looked at cleaning or recycling the database? It might be that it's large in size, but this is because of it attempting to keep space set aside for data that is no longer there.

HTH
 
Upvote 0
Top