Help with memory leak - Android Software Development

Hey guys. I've been looking around all over for info on the problem with my app. Nothing I found was a concrete answer. here's the problem. I made an app that works really well except it force closes when I hit the back button to finish activity and then start another of the same activity as before. It force closes once in a while when I do this, throwing a log cat error that says out of memory, pointing to where I fill my bitmap cache. There's two reasons im thinking it would be doing this. 1) My bitmap factory is having a problem or 2) I have the context of my activity stored as a variable so I can close activity and that is too much memory. I'm using a panel, which also may add to the problem. Also, another phone can't even start the activity the first time. Any help would be greatly appreciated. This is only problem on app and this fix will make it market ready.
Sent from my SCH-I500 using XDA App

Did you try to explicitly clean up the bitmap references? you should call Recycle() on every bitmap in your activity's onDestroy or wherever you do your cleaning. Another issue I had was with the Bitmap.CreateScaledBitmap method - it leaks, apparently. I made a small static method that uses a transform matrix and then calls Bitmap.CreateBitmap (the overload that takes a matrix, obviously). That change alone solved half my memory issues.
The thing about not loading at all on another phone might be a heap issue. My game loaded just great on my customized SGS, but on the emulator with 24mb of heap it crashed. The reason was that I pre-load all the sprites at the beginning, and apparently 24mb isn't that much
Solution was downscaling and lowering resolution and color depth for the sprites, not much possibilities here - too many bitmaps take too much memory...
I'm guessing the phone you tested likely has a smaller heap than the phone that doesn't make your app crash.
Of course all of the above is mostly guess work, but that's what I can supply right now

i have the problem fc too, but after i upgraded to 2.2. the seem the problem fixed automatically.

Thanks so much! I made it recycle my bitmaps, along with a few minor changes, and it worked great! Thanks for your help!
Sent from my SCH-I500 using XDA App

Related

How to prevent OS exiting my applications?

Hi,
I noticed that OS constantly unloads my applications.
Say, I visit some page using IE, then switch to another application, then switch back - it is usually at the same page, but, probably depending on idle time, it sporadically gets closed.
That said, when I go to IE again, it starts afresh on its initial page and I must reload my page again. Needless to say, in most cases this is unacceptable. (extra traffic, so it costs $$, also GPRS could become unavailable etc :x )
How do I PREVENT this behaviour?
Not only IE suffers, any application! Sporadically exits despite of fact there are tons of free memory and I would better free resources with another way than just closing what is required for me.
I have elder device with PocketPC 3.0 (Cassiopeia E-125) and it does NOT behave in such a way. Does not close even it has 4times less memory! Now I understand how nice it is.
While this problem persists, I forced to have both devices with me.
Please help me solving this!
Vadim.
I've noticed the same behavior randomly also. I don't have a fix, but you're not alone.
What ROM version are you using? There was an issue with the earlier ROMS in that there were too many programs running and when you launched another program the OS would terminate a background program to provide the necesssary process space.
The newer ROMs have solved this problem, but CheckNotify and ClearNotify (search the forum) will help with the earlier ROMs.
This is an old problem, related to the number of running processes.
Consult this thread
http://www.ppcw.net/?itemid=1645
which will show you how to solve it. Also the newer roms cut down on the number of processes at startup, which helps.
Surur
Mine is much more random than that described. Sometimes I can have a half dozen apps open with no problem, and sometimes a single app will close itself while I work in the phone or the Today screen.
Carlos said:
Mine is much more random than that described. Sometimes I can have a half dozen apps open with no problem, and sometimes a single app will close itself while I work in the phone or the Today screen.
Click to expand...
Click to collapse
Don't forget that we are talking processes, not appications, here. One app. may have many processes and multiple app's may use the same common processes. Therefore, launching one application can generate a number of new processes and that can push you over the limit (e.g. ActiveSync, which launches three or four I recall), so something gets nuked.
I understand, and was looking for a pattern, but there is none. In fact, it seems reversed, as it happens more often while I'm just out and about and less frequenty while the device is in the cradle. Very often it happens after a fresh boot with a single app running.
I may look at it more closely with a process viewer. It's not bugging me enough to make it a priority.
Thank you all for providing many help!
surur said:
This is an old problem, related to the number of running processes.
Consult this thread
http://www.ppcw.net/?itemid=1645
which will show you how to solve it. Also the newer roms cut down on the number of processes at startup, which helps.
Click to expand...
Click to collapse
That explains it all, many fruitful comments, and a prove that there could be no fix but just temporary solutions to reduce a problem a bit.
It is a bit larger problem in my case, because I use special sotware to support Russian.
Too bad MS can't recognize and fix such a big design mistakes.

[APP][21/11/2008] NoTSR - A very little tool to restore memory

Hi.
When using my Diamond I noticed some processes don't disappear when they should. They fill up memory. Either you kill 'em with some Task Manager, or you soft reset.
Don't wanna SR or kill processes manually? Let my thing do it for you!
NoTSR is a very very simple program which kills some predefined processes, based on my experience with Diamond.
Source code (eVC++ 4) is for you to use and modify whatever you want. However, it would be nice if you gave me some credit if using it!
Have fun!
p. s. Sorry for the icon.
If anyone is wondering, this is what it kills off (copied straight from the source code):
"Opera9.exe", // everything still loads well
"OperaPreL.exe", // after killing them
"pword.exe", // for some reason Pocket Word leaves its process even after leaving
"CommManager.exe", // other Office apps seem to be fixed
"AudioManager_eng.exe", // last ones are opened by manila for quicker loading of tabs.
"AlbumSearcher.exe" // killing AudioManager stops music and rewinds current track.
I keep getting a "Can't list processes" dialog box when I launch the app. I tried placing the NoTSR.exe within in the extracted NoTSR subdirectory and also outside the subdirectory.
JNGold said:
I keep getting a "Can't list processes" dialog box when I launch the app. I tried placing the NoTSR.exe within in the extracted NoTSR subdirectory and also outside the subdirectory.
Click to expand...
Click to collapse
I can confirm that.
What did we wrong? Do we have to place it in a special folder, like windows?
It worked for me, but my phone was very sluggish after running the app and I had to soft reset to bring it back to par.
Thanks for starting this development, there is definitely a gap to be filled by it, I use oxios hibernate and a task manager to finish off opera .exe, this is much easier to use and your icons not so bad either!
uniqueboy said:
It worked for me, but my phone was very sluggish after running the app and I had to soft reset to bring it back to par.
Thanks for starting this development, there is definitely a gap to be filled by it, I use oxios hibernate and a task manager to finish off opera .exe, this is much easier to use and your icons not so bad either!
Click to expand...
Click to collapse
Thanks for positive feedback. I wonder why th sluggish reaction. Loading of opera as well as some TF3D tabs will for sure be slower, but whole phone is weird. After all, it just kills and leaves (see src if unsure). I use NoTSR myself and I got no problems at all. Maybe you could test it again and if it slows down show the list of processes?
@others: try using the app with rest closed. It should work in any folder; I keep it in my docs and launch via Start.
Thanks again for interest!
same error message for me. sprint touch pro with jd6.1 rom
I can't reproduce that error to analyze and fix it, so I post new version which tells you what went wrong. Try with it.
trying now
kosherpig said:
Thanks for positive feedback. I wonder why th sluggish reaction. Loading of opera as well as some TF3D tabs will for sure be slower, but whole phone is weird. After all, it just kills and leaves (see src if unsure). I use NoTSR myself and I got no problems at all. Maybe you could test it again and if it slows down show the list of processes?
@others: try using the app with rest closed. It should work in any folder; I keep it in my docs and launch via Start.
Thanks again for interest!
Click to expand...
Click to collapse
OK, so I've been using the NoTSR app for a couple of days and I can't reproduce the lag that I had when I first ran it, odd. I think it may be something to do with the fact that when I first ran it it was from within file explorer, after using it I could not get explorer to open up again properly. Now I have put a shortcut in my windows/start up/programs folder and I am running it from my start menu everything seems just fine and is all working as it should with no sluggish side effect, so thanks again kosherpig for the very useful app.
SKTools Lite (free) comes with a small program called "Free up ram." During SKTools Lite install, it will tell you something about your windows version, just click through that and let it install.
Once it's installed, go to your programs page and you'll see it there: "Free Up RAM". Just run it once. It will look like nothing is opening, but its because it's working in the background. You'll get a message box very shortly telling you how much ram (in KB) you freed up.
http://s-k-tools.com/index.html?sktools/m_lite.html
I use it all the time. Brings me from 45 -50 down to 35-40. Lowest I've seen was 32%.
Our programs are slightly different. My one doesn't free RAM by itself; it closes processes which won't close by a "close all" command. And NoTSR is not resident (after all its name is No Terminate-Stay-Resident ). Its goal is to be as small as possible, also in term of occupied disk space (~9kB now). Maybe this SKTools and NoTSR could be used in conjunction to free up even more RAM?
And, I also got the error message 2 times.
1st when I was running FM radio.
2nd when I was at the Music tab.
I solved them:
1st by closing FM radio and invoking NoTSR. Everything went OK.
2nd switched to the Home tab. NoTSR failed again. Waited some seconds, ran again. OK now.
Solution: fails? Shut everything using the HTC task manager, go to today/home screen, and invoke NoTSR after some time. I can say the behavior is really weird, since my code doesn't depend on running apps.
However, I run NoTSR everytime after using Opera. I got that error 2 times in my whole usage.
Anyways. Thanks for all responses
I find "Oxios Hibernate" frees up more ram than sk tools "free up ram" does, it is also free, but must be run manually, a useful addition to any start menu.
I'm getting about 10 mb back with NoTSR after opera browsing, "free up ram" or "hibernate" practically nothing back after opera browsing. Basically if you use opera then this is a "must have".
A small update.
If you know when Oxios Hibernate works and NoTSR fails, check this exe out. I tried to contain the Hibernate in it.
This version is bugged.
Please use version from 1st post.
If you ran this version already perform a soft reset.
Sorry for inconvinience.
chronster said:
SKTools Lite (free) comes with a small program called "Free up ram." During SKTools Lite install, it will tell you something about your windows version, just click through that and let it install.
Once it's installed, go to your programs page and you'll see it there: "Free Up RAM". Just run it once. It will look like nothing is opening, but its because it's working in the background. You'll get a message box very shortly telling you how much ram (in KB) you freed up.
http://s-k-tools.com/index.html?sktools/m_lite.html
I use it all the time. Brings me from 45 -50 down to 35-40. Lowest I've seen was 32%.
Click to expand...
Click to collapse
it lowers your memory usage by 10%???
To me it goes from 63% to 61%...
On my Diamond
thats frustrating...
Hi there, trying to use this app I'm getting the same error as others...
"Can't list processes: The parameter is incorrect. (#0)"
Task Manager is empty, I've tried leaving it on the home screen for 20 secs and running it but still the same problem.
Any ideas? I'd really like to get this working as Dutty 3.1 does appear to suffer from this memory problem.
EDIT.... OK, did a reset and it's working fine. I'll play with it over the next day or so, and fingers crossed Dutty 3.1 will be good enough for me as I don't need YouTube.
EDIT2... Worked for a while, now has the same problem as earlier.
Are you using the version form 1st post?
If not, please use it.
By the way, something is really wrong... AFAIK "Invalid parameter" has error code 87, 0 is "success". I've looked at program code to see where I could mess up memory, but I saw no such places. Help with finding this bug (you've got the source) would be very appreciated.
hi kosherpig
can you add a settings file where we can put our personal process to stop?
I've try to modify the source but I'm not able to compile it
kosherpig said:
Are you using the version form 1st post?
If not, please use it.
By the way, something is really wrong... AFAIK "Invalid parameter" has error code 87, 0 is "success". I've looked at program code to see where I could mess up memory, but I saw no such places. Help with finding this bug (you've got the source) would be very appreciated.
Click to expand...
Click to collapse
Hi Kosherpig, I am using the version from the 1st post.
I'm happy to help finding the bug, but not sure what to do here! I THINK it stopped working after I used TomTom7, but can't be sure.
It's only 1635 and it's down to 16% battery already (I think this is a problem with Dutty 3.1), so I don't want to do lots of tests. However, when I'm home and charging it, I'll try each app individually until I pin point which one "causes" the problem.
Does this help? Anything else you want me to try?
Hi kosherpig, getting on great with NoTSR now, I just have one small idea that it would be nice to show the memory stats in the pop up dialogue in a similar way to oxios hibernate. Unless of course this would significantly affect the size and speed of the app, in that case I think it is easy enough to check on the memory usage other ways with a couple of quick taps.

[GUIDE] About Android and Optimizing Sony Xperia X10

Since Sony Xperia X10 is now running on 2.1, topics related to 1.6 is not mentioned here.
This thread are created based on compilation of other threads related to optimization, and meant as an entry point for user interested in optimization.
Understanding your Android
Just to put something short, so we can understand our Android and some points related to optimization better.
Android is an open source operating system owned by Google that is maintained by Android Open Source Project (AOSP). The operating system is based on modified Linux kernel, where most of the application is written in Java language and running on DalvikJVM.
Android do things differently than old generation OS like Symbian, and below is the explanation related to performance.
Unlike Symbian, Android designed to have as many as application loaded and running in the OS, it maintain list of least used application that will be unloaded when a requests for more memory is made when the free OS memory is already low.
These are the nature of JVM, where allocation and deallocation of memory is managed by garbage collector as doing things in bulk is faster then working with small chunks. So you don't have to be alarmed when you open a memory viewer application and see your Android is running on low memory. Freeing RAM with task killer is only momentarily, as you uses the phone again, the free memory will goes down again.
Android phones stores system application, data and files internally in NAND flash area and stores user data in internal memory storage or external storage such as SD cards. This memory is different than your operating sytem memory.
Operating system memory is memory allocated for the kernel, native application and most application you download from market. Installing a lot of application will not directly reduce free RAM, nor uninstalling or removing files will increase free RAM directly. Action such as removing ringtones, wallpaper and even Sony PC Companion ISO will not free your RAM
In general there are two type of android application. One is a standalone application that only run if you open the application, and the other one is running even you haven't open the application which called service.
By design, guideline and suggested practice, application should not continue to run lengthy processing when it get pushed to background via home button, back button or switching to other application; properly build application will just go idle. Which means you should be less paranoid about application eating you processing power.
But service is meant to run lengthy operation as they don't have user interface and runs in background. Some service meanth for pushing or pulling data from internet, reading your files and do processing like playing songs, or just doing something then update the widget just to make you happy. Unnecessary services are the things that you should be aiming if you want to optimize your Android.
General FAQ about Optimizing Sony Xperia X10 2.1
I just updated to 2.1 and my phone really feel slower than 1.6
Since you had been using 1.6 for quite some time, your SD card should have quite a lot of photo and media. Just after you updated to 2.1, and add your Google and maybe Facebook account, the new Face Recognition service is actually already starting to scans all your photo, then when your Google and Facebook contact arrived, it will try it best to match photo and contact. This new Face Recognition really kicks hard in your processor, then after a while your phone will be as fast and even better than old stock 1.6.
I still feel that the phone is slow, is there any simple and quick way to optimize
The simple and quick to optimize your phone instantly is by changing the 2.1 dalvikvm to JIT capable dalvikjvm. You can read and apply them by reading the thread referred below, but before you do that open the below link in background tab and please do read more first.
Android 2.1 OPTIMISER V002 by Jerpelea
2.1 Customizer v0.99.1 by ttxdragon
Both optimizer contains script that will erase your "junk/unused" application from your phone, be sure to read them first before executing. My suggestion is you apply JIT modification first, before going optimizing by remove your "junk/unused" application.
Please do remember that you have to Root your X10 first.
How to root the phone
You can root the phone using methods below.
OneClick z4root Android Application
SuperOneClick Windows Application
Is [INSERT APP NAME] here is save to remove?
By removing unused application, you will gain certain amount of performance gain. Below are the links with app list.
2.1 Customizer v0.99.1 by ttxdragon
Official List of Apps that Can be Removed from a 2.1 x10 by exekias
And still a lot more in other Sony Ericsson X10 forum section but those two is quite complete
And in case you forgot to make backup you can go to
2.1 System Apps - In Case You've Deleted Them by XperiaX10iUser
After doing all that my Quadrant Benchmark is still low
You should run Quadrant as least two or three time or until you get best score, the first one usually yield low score, because a lot of memory allocation process to Quadrant happening during the first run.
Tuning Utilities
Memory Usage - Application to see how much memory used by your application and services
Advanced Task Manager - Application to see is your application running on foreground, background or idle and its memory usage
Quadrant Standard - General benchmarking tools to see if your changes make improvement
Linpack - Processor benchmarking
Titanium Backup Pro - Back up application, the paid version can freeze your app rather then uninstalling it.
Fine Tuning Guide
About Widget, Application shortcut and Live Wallpaper
Even though widgets looks really good in your phone, some widgets required simple periodic process for updating its display, some have a full blown service running to support it. A very instant example that you can see in your phone is the Power Control widget and the new Status Switch widget.
Power Control widget update triggered by configuration change such as wifi on and off, while Status Switch widget which have a battery level is triggered by a running service. Just put Status Switch widget then go to Settings -> Application -> Running Services. Then you will see there a Status Switch Update service running in background to update the battery level.
By selectively put widgets on your home screen, you can gain extra processing and memory. Timescape widget is even worse, it have three service running to support it.
Application shortcuts also uses extra memory in your home screen app and your home screen app is usually system persistent, reducing number of shortcut will give extra RAM and reducing the required rendering process during scroll.
Live Wallpaper just as the name said looks really nice and require extra memory and process of course.
Tuning via build.prop
Some value can be added and modified into build to increase the performance of X10.
dalvik.vm.heapsize=32m
This will change the maximum memory size per application. If you decrease the value, smaller application starts faster, but big application like games will prone to crash, if you increase the value too much, smaller application takes longer to start, but big application will extra gain benefit from less garbage collecting.
Reference: Test: How changing the max amount of memory per VM Heap can effect your ROM (Cyanogen)
windowsmgr.max_events_per_sec=60
This will change the maximum number of touch screen gesture events per second, the bigger the value, the smoother the scrolling will be
There still some more build.prop tweaks that you can do, but not all of them will be processed by X10 as each device behave differently.
reservation for more article to go
Nice clean guide, should help newcomers. Good work!
synlar said:
Nice clean guide, should help newcomers. Good work!
Click to expand...
Click to collapse
Thanks, but i am quite depressed after reading it my self and found that i make a lot of typo. Had to revise and revise again.. lol.
Nice piece of work there Xeviro..
Can you post your build.prop please i cant find the windowsmgr.max_events_per_sec=60 one in mine.
Wolfbreak said:
Can you post your build.prop please i cant find the windowsmgr.max_events_per_sec=60 one in mine.
Click to expand...
Click to collapse
That one you add by your self to you build.prop. If you look further in google, there still a lot of other build properties that you can set to Android.
There is another way to add and test build.prop instantly by using adb shell command "setprop key value" and "getprop key". Some property will take effect immediately, some require you to reboot.
How do you prove that the windowsmgr.max_events_per_sec=60 actually works? After applying that I tried input benchmark and it still showed 33hz.
ooidort said:
How do you prove that the windowsmgr.max_events_per_sec=60 actually works? After applying that I tried input benchmark and it still showed 33hz.
Click to expand...
Click to collapse
Ok, i just checked, that for this build.prop property to take effect, you need to reboot the device first. I just test on my, giving 10 and 200 in value. With 10, the input benchmark showing less then 20hz most of the time, while with 200 it gives me 40hz+.
Also you can see if you scroll the app list with 10 and 200 value, you can see the difference.
xeviro said:
Ok, i just checked, that for this build.prop property to take effect, you need to reboot the device first. I just test on my, giving 10 and 200 in value. With 10, the input benchmark showing less then 20hz most of the time, while with 200 it gives me 40hz+.
Also you can see if you scroll the app list with 10 and 200 value, you can see the difference.
Click to expand...
Click to collapse
I definitely notice the difference between 10 and 200, but it still doesn't go above 33hz... Maybe it's the framerate cap doing it's thing?
xeviro said:
Thanks, but i am quite depressed after reading it my self and found that i make a lot of typo. Had to revise and revise again.. lol.
Click to expand...
Click to collapse
Good write up! I was actually going to say something about the typos/errors, because I'm a jerk, but, you noticed them too, so I feel satisfied.
I hope people will read your little intro about RAM and realize a task killer's real purpose is to kill rogue services that kill battery.
xeviro said:
That one you add by your self to you build.prop. If you look further in google, there still a lot of other build properties that you can set to Android.
There is another way to add and test build.prop instantly by using adb shell command "setprop key value" and "getprop key". Some property will take effect immediately, some require you to reboot.
Click to expand...
Click to collapse
But where do i need them to add? At Beginning or at End or Middle?
iead1 said:
Good write up! I was actually going to say something about the typos/errors, because I'm a jerk, but, you noticed them too, so I feel satisfied.
I hope people will read your little intro about RAM and realize a task killer's real purpose is to kill rogue services that kill battery.
Click to expand...
Click to collapse
Please forgive my typo and grammars, i life in country where people simplify their way of communication. I cannot talk proper now. hahaha
Wolfbreak said:
But where do i need them to add? At Beginning or at End or Middle?
Click to expand...
Click to collapse
Anywhere
xeviro said:
Please forgive my typo and grammars, i life in country where people simplify their way of communication. I cannot talk proper now. hahaha
Anywhere
Click to expand...
Click to collapse
If i add this to the end of my build.prop my phone does not accept SIM unlock code anymore .... ??
EDIT: Strange, second time it worked ... btw. what is the default value ?
Ive added dalvik.vm.heapsize=32m to see what diff it will make and well..
wow.. it killed my phone.
It will show sony ericsson on the screen when you turn it on and just stay there!
So yeah... how can i fix this?
It's bricked, you'll need to reflash the software!
:-(
OP- Great thread, thank you!
Post on my Rooted 2.1 X10i using Tapatalk Pro and Swype
Yeah i knida noticed...
fixed now but im not trying that heapsize thing again..
Anyone here have the original/untouched nordic build.prop? I'm really appreciate it if you share it here. ^_^
Sent from my Xperia X10i (2.1 and rooted) using XDA app
Seansmit17 said:
Ive added dalvik.vm.heapsize=32m to see what diff it will make and well..
wow.. it killed my phone.
It will show sony ericsson on the screen when you turn it on and just stay there!
So yeah... how can i fix this?
Click to expand...
Click to collapse
Seansmit17 said:
Yeah i knida noticed...
fixed now but im not trying that heapsize thing again..
Click to expand...
Click to collapse
Its working correctly in my phone, and this heapsize settings is the most common one in android modding. you go check google and see the results.
I also attached build.prop from my phone.

Cautionary Tale: Always lock your Arrays in game development

Thought I would record my troubles with a game render loop and a logic engine given a particular bug has swallowed up about a week of my time. I am posting it incase anyone else happens to have the same problem/symptomns.
It originated when I wrote the LogicEngine which has an ArrayList of GameObjects and iterates through them deleting them as nessesary depending on the results of thier processStep.
The render thread would occasionally crash when something was deleted from the array while the list was being drawn but this happened quite rarely. No problem I thought, I'll just catch the out of bounds exception and it will get displayed on the next frame however many milliseconds later.
This all went well for 3 months of coding till I got to programming terrain where about 300 blocks were all displayed gradually scrolling down the screen. The blocks would flash intermittently but in sections not all at once.
At first I thought it was too many blocks for the LogicEngines collision detection so I doubled the size of the blocks. Then I thought it might be overhead allocating memory for the blocks and preloaded them in the constructor. Eventually in despair I disabled the deletion of blocks once they went offscreen and noticed the flashing stopped. This was the point I realised what was happening: The LogicEngine would delete a row of blocks because they went offscreen and the Renderer would be half way through drawing and instead of crashing it would just skip x blocks wherever it was in the for loop at the time that the LogicEngine removed them.
Wow I feel stupid, especially because of the lazy Exception catching solution I originally implemented which masked the problem for so long.
Code:
GameRender.java
//draw obstacles
theLogicEngine.objectsObstaclesLock.writeLock().lock();
for(int i=0 ; i<theLogicEngine.objectsObstacles.size();i++)
{
drawObject(theLogicEngine.objectsObstacles.get(i));
}
theLogicEngine.objectsObstaclesLock.writeLock().unlock();
LogicEngine.java
for(int i=0;i<objectsObstacles.size();i++)
if(objectsObstacles.get(i).processStep(this)) //we are to delete this object
{
objectsObstaclesLock.writeLock().lock();
//remove self if necessary
//move object returned true so delete object
GameObject toDelete = objectsObstacles.get(i);
objectsObstacles.remove(i);
toDelete.dispose();
i--;
objectsObstaclesLock.writeLock().unlock();
}
TLDR: If you have an ArrayList that can be edited by one thread, make sure you lock it rather than just catching the ArrayOutOfBoundsException
Glad you figured it out
I am still impressed that you can write Android games using these techniques. Is your game low-res or is Dalvik that powerful?
I mean, you are using Java, which is one thing, but then you use ArrayList and you delete objects as you go. I take this to mean that you do not recycle them in a pool.
Am I correct?
cyansmoker said:
Glad you figured it out
I am still impressed that you can write Android games using these techniques. Is your game low-res or is Dalvik that powerful?
I mean, you are using Java, which is one thing, but then you use ArrayList and you delete objects as you go. I take this to mean that you do not recycle them in a pool.
Am I correct?
Click to expand...
Click to collapse
ArrayList is self managing.
All of Java's garbage collection is done automatically. As a Java dev u can call System.gc but this only suggest the system attempt gc.
Dalvik is pretty good, but anything extensive I would go native...
Sent from my Galaxy Nexus using Tapatalk
jug6ernaut said:
ArrayList is self managing.
Click to expand...
Click to collapse
Right. But then there is the memory consumption issue. That's why I typically do things as described in this blog entry.
jug6ernaut said:
All of Java's garbage collection is done automatically. As a Java dev u can call System.gc but this only suggest the system attempt gc.
Click to expand...
Click to collapse
Although in System.gc()'s defense I've always observed that it was run immediately in Sun's ref. implementation. Not sure about Dalvik.
But overall I agree with your conclusion.
cyansmoker said:
I am still impressed that you can write Android games using these techniques. Is your game low-res or is Dalvik that powerful?
Click to expand...
Click to collapse
So far I have not been having any performance issues. The ArrayLists contain GameObjects which are quite lightweight memory wise as they do not contain Textures.
Textures are maintained in separate dictionary with a string key.
I did try recycling GameObjects in one location where I was spawning / destroying a lot but it didn't really seem to impact performance much.
I think my biggest area for optimisation at the moment is in collision direction. Currently there are about 5 different ArrayLists (Obstacles, Enemies, Players, Player Bullets, Enemy Bullets etc) only those that interact are tested for collision (Vector2d distance < objects collision radius). I think theres probably opportunity to split it further into quads.
I've yet to build in proper optimisation checking but it plays fine in 320x480 with ~100 enemies on screen and 4 player ships with maybe 20 bullets on screen at once with a turnover of 5/10 GameObjects a second. Even with this number though Texture memory usage is low with most enemies between 16x16 and 48x48.
I think libgdx and the behaviours library I use are pretty optimised.

Main layout makes lags

Hello guys!
Here is my new problem. When I add background image to my main layout (RelativeLayout) my listView, and horizontalScrollView (they are both on my main page) are taking lags and they stopped moving smoothly. I dont know what can i do, please help.
Matma said:
Hello guys!
Here is my new problem. When I add background image to my main layout (RelativeLayout) my listView, and horizontalScrollView (they are both on my main page) are taking lags and they stopped moving smoothly. I dont know what can i do, please help.
Click to expand...
Click to collapse
Try switching all the operation to other threads and keep the main thread only for displaying only GUI related stuff.
Sent from my Moto G using XDA Free mobile app
Since you've mentioned a background image, I would make sure that it's both a reasonable size and that you aren't setting it over and over again. Lots of bitmap processing really slows down Android apps because it's very computationally expensive compared to everything else.
maclynb said:
Since you've mentioned a background image, I would make sure that it's both a reasonable size and that you aren't setting it over and over again. Lots of bitmap processing really slows down Android apps because it's very computationally expensive compared to everything else.
Click to expand...
Click to collapse
Exactly. id be looking at the filesize before anythibg else though.

Categories

Resources