开发者

Is this a memory leak? - the Context is the Android Context

开发者 https://www.devze.com 2023-04-11 13:04 出处:网络
I ran into out of memory exception on my app. I have code that, in general, does something like below:

I ran into out of memory exception on my app. I have code that, in general, does something like below:

while(true)
{
       A.foo(this);
}


public class A
{
    publ开发者_如何学编程ic static void foo(Context c)
    {
       return;
    }
}

Will it leak?


No reference to the Context is held after A.foo(Context) is executed (according to the code you have provided), so you probably do not need to worry about A.foo.

However, having a thread that is running a while(true) loop that never exits can lead to zombie threads that leak out memory - which is more apparent when it holds a reference to a Context.

0

精彩评论

暂无评论...
验证码 换一张
取 消