java.lang.OutOfMemoryError:未能分配46个字节的分配,其中0个空闲字节和-6MB直到OOM

时间:2018-08-20 06:22:26

标签: android out-of-memory

我有一个简单的线程,该线程每分钟在sqlite上运行一个非常简单的查询,并且仅从数据库中获取一行。这个SQL查询确实很小。但是我有时会从某些客户的设备收到崩溃报告:

java.lang.OutOfMemoryError: Failed to allocate a 46 byte allocation with 0 free bytes and -6MB until OOM

很遗憾,我没有更多有关此问题的数据。我该如何解决? 46字节不足以引发OutOfMemoryError!

这是我的话题

@Override
protected void onResume() {
    super.onResume();
    if (locationThread == null) {
        locationThread = new Thread(new Runnable() {
            @Override
            public void run() {
                locationmanager.LocationManager locationManager = new LocationManager(VasActivity.this);
                while (!VasActivity.this.isFinishing()) {
                    try {
                        lastLocation = locationManager.getLastLocation(LocationManager.Accuracy.TrackingAccuracy, 120);
                        Thread.sleep(60000);
                    } catch (InterruptedException ignored) {

                    }
                }
            }
        });
        locationThread.start();
    }
}

这是getLatLocation()方法:

@Nullable
public LocationModel getLastLocation(float accuracy, int timeSpan) {
    LocationModel locationModel = getItem(new Query().from(Location.LocationTbl)
            .whereAnd(Criteria.lesserThan(Location.Accuracy, accuracy)
                    .and(Criteria.isNull(Location.EventType))).orderByDescending(Location.Date));

    if (locationModel == null)
        return null;
    long currentTime = new Date().getTime();
    long pointTime = locationModel.Date.getTime();
    long t = (currentTime - pointTime) / 1000;
    if (t < timeSpan)
        return locationModel;
    else
        return null;
}

和新的query()返回以下原始查询:

SELECT * FROM "Location" where Accuracy < accuracy ORDER BY Date LIMIT 1;

当用户关闭活动时,我不会停止线程。是问题的原因吗?我有一个循环,每次迭代都等待一分钟,然后执行某些操作。如果用户取消激活 y

,我就会中断循环

0 个答案:

没有答案