I often use AsyncTask
because
AsyncTask
is have ThreadPool,
so Even if the thread grows indefinitely, Memory is managed to avoid stress.
but, recently occur OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
so, I found the suspicious part.
public static class getPubIpAddress extends AsyncTask<Void, Void ,String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
try {
URL pubIp = new URL("https://myserver.co.kr/ipaddr.php");
BufferedReader in = BufferedReader(new InputStreamReader(
pubIp.openStream()));
String pub = in.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return pub;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
this asynctask get public ip. and execute when network connect, change network.
could this asynctask cause outofmemory on android?
thanks:)