Hello.
Yes that is what i want it to do.
This is a background thread that is started RunThread = true on
"onResume()" and i set it false on "onPause()" and on "onStop()".
So as long the activity is active then this should run in background and
connect a web server and later in the code iam processing the String xml (i
disabled that part now when iam locking for the memory leak)
Here is a short period of my logcat when this loop is running.
07-30 04:19:59.205: D/dalvikvm(1863): GC_CONCURRENT freed 325K, 21% free
3528K/4432K, paused 28ms+27ms, total 210ms
07-30 04:20:00.626: D/dalvikvm(1863): GC_CONCURRENT freed 433K, 21% free
3509K/4432K, paused 22ms+23ms, total 226ms
07-30 04:20:02.037: D/dalvikvm(1863): GC_CONCURRENT freed 407K, 21% free
3506K/4432K, paused 31ms+23ms, total 151ms
07-30 04:20:03.887: D/dalvikvm(1863): GC_CONCURRENT freed 412K, 21% free
3507K/4432K, paused 73ms+48ms, total 271ms
07-30 04:20:05.235: D/dalvikvm(1863): GC_CONCURRENT freed 408K, 21% free
3503K/4432K, paused 194ms+24ms, total 324ms
07-30 04:20:06.555: D/dalvikvm(1863): GC_CONCURRENT freed 401K, 21% free
3505K/4432K, paused 109ms+153ms, total 390ms
07-30 04:20:07.917: D/dalvikvm(1863): GC_CONCURRENT freed 412K, 21% free
3510K/4432K, paused 144ms+68ms, total 396ms
07-30 04:20:09.167: D/dalvikvm(1863): GC_CONCURRENT freed 408K, 21% free
3510K/4432K, paused 125ms+5ms, total 295ms
07-30 04:20:10.736: D/dalvikvm(1863): GC_CONCURRENT freed 413K, 21% free
3503K/4432K, paused 129ms+144ms, total 361ms
07-30 04:20:12.045: D/dalvikvm(1863): GC_CONCURRENT freed 401K, 21% free
3509K/4432K, paused 117ms+31ms, total 283ms
07-30 04:20:13.715: D/dalvikvm(1863): GC_CONCURRENT freed 412K, 21% free
3508K/4432K, paused 106ms+35ms, total 238ms
07-30 04:20:15.335: D/dalvikvm(1863): GC_CONCURRENT freed 414K, 21% free
3506K/4432K, paused 15ms+129ms, total 349ms
07-30 04:20:16.695: D/dalvikvm(1863): GC_CONCURRENT freed 402K, 21% free
3511K/4432K, paused 103ms+20ms, total 222ms
07-30 04:20:17.675: D/dalvikvm(1863): GC_CONCURRENT freed 406K, 22% free
3496K/4432K, paused 5ms+4ms, total 81ms
07-30 04:20:19.337: D/dalvikvm(1863): GC_CONCURRENT freed 401K, 21% free
3509K/4432K, paused 103ms+135ms, total 451ms
07-30 04:20:21.045: D/dalvikvm(1863): GC_CONCURRENT freed 412K, 21% free
3508K/4432K, paused 97ms+137ms, total 365ms
07-30 04:20:22.536: D/dalvikvm(1863): GC_CONCURRENT freed 415K, 20% free
3558K/4432K, paused 113ms+179ms, total 436ms
07-30 04:20:24.105: D/dalvikvm(1863): GC_CONCURRENT freed 452K, 21% free
3531K/4432K, paused 5ms+31ms, total 136ms
07-30 04:20:25.655: D/dalvikvm(1863): GC_CONCURRENT freed 415K, 21% free
3537K/4432K, paused 152ms+129ms, total 414ms
07-30 04:20:27.277: D/dalvikvm(1863): GC_CONCURRENT freed 435K, 21% free
3508K/4432K, paused 140ms+41ms, total 288ms
07-30 04:20:28.655: D/dalvikvm(1863): GC_CONCURRENT freed 412K, 21% free
3515K/4432K, paused 197ms+132ms, total 396ms
07-30 04:20:29.975: D/dalvikvm(1863): GC_CONCURRENT freed 427K, 22% free
3496K/4432K, paused 138ms+5ms, total 311ms
07-30 04:20:31.305: D/dalvikvm(1863): GC_CONCURRENT freed 397K, 21% free
3510K/4432K, paused 88ms+182ms, total 403ms
07-30 04:20:32.797: D/dalvikvm(1863): GC_CONCURRENT freed 406K, 21% free
3507K/4432K, paused 119ms+22ms, total 285ms
07-30 04:20:34.385: D/dalvikvm(1863): GC_CONCURRENT freed 407K, 21% free
3507K/4432K, paused 4ms+123ms, total 256ms
07-30 04:20:35.615: D/dalvikvm(1863): GC_CONCURRENT freed 407K, 21% free
3512K/4432K, paused 99ms+170ms, total 406ms
07-30 04:20:36.895: D/dalvikvm(1863): GC_CONCURRENT freed 415K, 22% free
3500K/4432K, paused 106ms+5ms, total 239ms
07-30 04:20:38.395: D/dalvikvm(1863): GC_CONCURRENT freed 439K, 21% free
3538K/4432K, paused 155ms+187ms, total 481ms
07-30 04:20:39.475: D/dalvikvm(1863): GC_CONCURRENT freed 420K, 21% free
3534K/4432K, paused 5ms+133ms, total 250ms
07-30 04:20:40.815: D/dalvikvm(1863): GC_CONCURRENT freed 421K, 21% free
3528K/4432K, paused 114ms+136ms, total 425ms
07-30 04:20:42.065: D/dalvikvm(1863): GC_CONCURRENT freed 429K, 21% free
3506K/4432K, paused 115ms+132ms, total 383ms
07-30 04:20:43.295: D/dalvikvm(1863): GC_CONCURRENT freed 411K, 21% free
3504K/4432K, paused 109ms+33ms, total 247ms
07-30 04:20:44.575: D/dalvikvm(1863): GC_CONCURRENT freed 408K, 21% free
3510K/4432K, paused 15ms+21ms, total 175ms
Den tisdagen den 30:e juli 2013 kl. 03:42:13 UTC+2 skrev RichardC:
>
> Your while loop starting
> >while (RunThread) {
>
> in your run() method will loop until an external event resets RunThread.
> Is this what you intended? Try putting a log line inside the while loop
> and watching the LogCat output.
>
> On Monday, July 29, 2013 7:22:12 AM UTC+1, Kristoffer wrote:
>>
>> Hello.
>> Iam having trouble with memory leak it will finaly cause the app to force
>> close.
>> I have stripped down my code just to find where the problem is and i
>> located it to my httpclient.
>>
>> When i run this code iam geting many GC_Concurrent freed.
>> if i add a Thread.sleep(1000); then i will ofcourse get less warnings but
>> my guess is that there is still some problem with the code i run.
>> Is there a way i could prevent the problem.
>>
>> Here is the code:
>>
>> Thread c = new Thread() {
>> @Override
>> public void run() {
>> String xml;
>> UsernamePasswordCredentials creds = new
>> UsernamePasswordCredentials("username", "password");
>> HttpGet httpGet;
>> HttpClient httpClient;
>> HttpResponse httpResponse;
>> HttpEntity httpEntity;
>> while (RunThread) {
>>
>> try {
>> httpClient = HttpClientFactory.getThreadSafeClient();
>> httpGet = new HttpGet("http://ipaddress/list?format=xml");
>> httpGet.addHeader(new BasicScheme().authenticate(creds,
>> httpGet));
>> httpResponse = httpClient.execute(httpGet);
>> httpEntity = httpResponse.getEntity();
>> xml = EntityUtils.toString(httpEntity, "UTF-8");
>>
>>
>> } catch (Exception e) {
>> e.printStackTrace();
>>
>> }
>> }
>> };
>> c.start();
>> }
>>
>> And here is the class HttpClientFactory
>>
>> public class HttpClientFactory {
>>
>> private static DefaultHttpClient client;
>>
>> public synchronized static DefaultHttpClient getThreadSafeClient() {
>>
>> if (client != null)
>> return client;
>>
>> client = new DefaultHttpClient();
>>
>> ClientConnectionManager mgr = client.getConnectionManager();
>>
>> HttpParams params = client.getParams();
>> params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
>> 10000);
>> params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);
>> client = new DefaultHttpClient(
>> new ThreadSafeClientConnManager(params,
>> mgr.getSchemeRegistry()), params);
>>
>> return client;
>> }
>> }
>>
>>
>> Have a made some huge mistage in the code that is causing this issue?
>>
>
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.