smanikandan14 / ThinDownloadManager

To download files and to avoid using DOWNLOAD_WITHOUT_NOTIFICATION permission if you are using Android's DownloadManager in your apps.
Apache License 2.0
783 stars 186 forks source link

DownloadStatusListener cause activity leak #49

Closed ghost closed 8 years ago

ghost commented 8 years ago

When I use a DownloadStatusListener in a activity, it will cause memory leak. The ThinDownloadManager.release() seems not consider this. Could you please fix it?

smanikandan14 commented 8 years ago

I don't think so there is any memory leak. Once you can release() on ThinDownloadManager instance. All the DownloadRequests are removed from the set which DownloadQueue maintains and also the blocking queue is set to null. So all the DownloadRequest objects which is passed to ThinDownloadManager is now orphan and those will be garbage collected.

    void release() {
        if (mCurrentRequests != null) {
            synchronized (mCurrentRequests) {
                mCurrentRequests.clear();
                mCurrentRequests = null;
            }
        }

        if (mDownloadQueue != null) {
            mDownloadQueue = null;
        }
               .......
               .......
}

If you see any memory leaks through MAT or DDMS. Please file a new issue.