0

我试图在特定的 x 秒刷新图像并在几分钟后出现内存泄漏。

我正在获取以下代码

try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
byte[] imageBytes = IOUtils.toByteArray(response.getEntity().getContent());
final Bitmap bmp = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
return bmp;
}

然后在一定时间后刷新:REFRESH_DELAY = 2000 REFRESH_DELAY_SLOW = 6000

public void onResume() {
super.onResume();
mThreadPool = Executors.newScheduledThreadPool(2);
mBackgroundTask = mThreadPool.scheduleWithFixedDelay(mRefreshRunable,0,Connectivity.isConnectedFast(getActivity()) ? Config.REFRESH_DELAY : Config.REFRESH_DELAY_SLOW,
TimeUnit.MILLISECONDS);
}

我得到的日志:

GC_FOR_ALLOC freed 1286K, 16% free 21943K/26064K, paused 44ms, total 44ms
GC_FOR_ALLOC freed 1296K, 16% free 21943K/26064K, paused 44ms, total 44ms
GC_FOR_ALLOC freed 1285K, 16% free 21943K/26064K, paused 44ms, total 44ms
GC_FOR_ALLOC freed 1286K, 16% free 21943K/26064K, paused 44ms, total 45ms
GC_FOR_ALLOC freed 1285K, 16% free 21943K/26064K, paused 47ms, total 48ms
GC_FOR_ALLOC freed 1286K, 16% free 21943K/26064K, paused 44ms, total 45ms
GC_FOR_ALLOC freed 1285K, 16% free 21943K/26064K, paused 43ms, total 44ms
GC_FOR_ALLOC freed 1286K, 16% free 21943K/26064K, paused 44ms, total 45ms
GC_FOR_ALLOC freed 1285K, 16% free 21943K/26064K, paused 44ms, total 45ms
4

0 回答 0