I have used AsyncTask for Downloading list of files from server.
At a time only one file is downloaded and after completion of one file another download starts. But downloading of file makes my application to use large amount of CPU more than 30% to 50% and also more amount of RAM.
Please help how to resolve this problem. Can we do any customization so that it use less amount of CPU
Related
I am thinking of making a download manager for Android.One of the functionality I want is to Download a file in small chunks on different threads for increasing download speed.I want to know how can this increase download speed and in how many parts to divide the file in.
my Android app seems to use too much cache space. The apk is less than 2 MB, but the App uses about 5 MB of cache. Now I want to find out what could use that much space.
Maybe it's the background image, which is a 700 KB Jpg (it is a photo)?
I don't store any data explicitly in the cache, so I wonder where these 5 MB come from.
Thanks for your help.
You can try to check the Heap and Allocation Tracker of your application on DDMS
http://developer.android.com/guide/developing/debugging/ddms.html
To start, thanks for taking the time to look over my question. I am currently having problems with memory spiking in the application I am developing.
My intent is to be able to download and process large amounts of HTML data, currently the cause is from large base64 encoded images nested in the HTML which I understand is not ideal for use on a mobile platform. For the record, I am currently testing on a Samsung Galaxy S. Also, this problem does not occur on the Galaxy Nexus due to more memory allocation per application.
My problem is that while processing a large chunk of HTML data of approximately 2.8mb, the memory heap increases to around 27-29mb but the allocated memory never passes beyond 18-19mb. When the HTML has been processed, saved and displayed the allocated memory returns to around 3-4mb. If I was to then download and process this HTML again, the process repeats and I get the same memory use, except it seems to increase the heap further (which to me doesn't seem necessary), at this point I receive an Out of memory error.
When I do receive this error it is normally while downloading the HTML using HttpGet or while extracting the data from disk using a StringBuffer. Occasionally it is caused by a Bitmap during an XML inflation.
Any help would be greatly appreciated.
There is little you can do if you really need that amount of memory. Phones have limited memory.
Dealocating memory is not instantaneous. It might take several iterations to free all the memory (and each iteration might be executed a few seconds apart).
It's frequent to have problems with too much memory used by images/drawables. Some times it's a memory leak; other times it's not possible to say what is causing it.
I've also had problems parsing large xml files. My solution was spliting those files into smaller ones. Another possibility is considering the advantages and disadvantages of different xml parsers (first google result: SAX parser vs XML pull parser). Maybe using some thirdparty implementation specially developed with memory usage concerns? One third option is using a server to convert the xml file to a more efficient format.
The best practice is not to allocate lots of memory. Process the data in-stream as you're reading it from the network, or stream it to disk and then read from there. The android:largeHeap option is available on all devices running Android 3.0 or above, but that only increases the amount you can allocate not remove the limit altogether.
I want to load a text file in a wordprocessing apps. But I get out of memory error when files are of too big. I finalized that I can load upto 1 MB files. But sometimes I get out of memory even for 1MB files. But I have to say before loading whether I can load files or not.
I tried for solution of finding maximum possible available memory, apart from freeMemory(),
that is freememory + (maxmemory - totalmemory) which will give the total possible available memory for the application. (Say it will be around 18MB to 20 MB). But I get outofMemory error after completely utilizing the heap. say for example(24 MB).
My question is really that (18MB to 20 mb) of "maximum possible available memory" is utilized for allocation when loading 1MB file.
How much of memory should be available to load 1MB file.
How can I roughly compute it.
Is there any way out of PSS, Privatedirty. I couldn't understand much about PSS. But I couldn't get much info regarding of summing up in article "How to discover memory usage of my application in Android"
Thanks
Remember, the way you store the files in variables matters quite a lot. Using char array manually is one of the most memory-efficient ways, but you still need to account for every character taking 16 bits, or 2 bytes. So, if you have text file using some 8-bit encoding and you load it into char array, it takes twice as much space.
I have A LOT of (optional) audio files.. I have 6400 audio files, with average size ~40 kb each, and total size ~400 mb..
I was wondering how will I download the files, Is it better to:
download a .zip file and then extract .. less bandwidth , more sdcard space requireed , more cpu to unzip..
download all the files (no .zip file)... more bandwidth , less sdcard and less cpu..
What is more reasonable?
Do a little test first...
Most audio files are already compressed, and Zipping them does not always reduce the size.
And if you can get only a small reduction with a high compression (= high CPU demand) setting then zipping will not be worth it.
You will have to measure to see on what side of the tipping point your files are.
Zipping should you give you a much faster download, as a single connection for download will be faster than openning 6400 HTTP request. (for small files, the time it takes to download is lower than the time it takes to open the connection. But the connection opening is constant, so for a large file you'll have much less time spend on opening connections.)
However, and that's the big point, most users won't be able to download 400MB easily without the network connection dropping. I'd suggest a middle way. Package the audio files into chunks or say 64 files each, (best in directories for faster access and reference) and download 64 files in a single zip or tar for that matter. I'd go with a non-compressing format, as the zipping won't give you much size reduction.
That way, you won't have to worry much about the download failing, and you'll have easy progress tracking.
However, i'd think about if you really need that many files in the first place.
Look if you either just have one biger mp3 file in which you can just play certain areas (just skipping inside the file) when you need it.
I'd also give a thought to lazy loading, just load the files when you need them
There's no need to compress etc .mp3 .flac .ogg but if it's for example a wave file you can compress the size pretty much.