MapCache icon indicating copy to clipboard operation
MapCache copied to clipboard

[Serious bug] Constant memory increase until crash when cache reaches capacity

Open quinncnl opened this issue 4 years ago • 3 comments

Hi @merlos ,

I encountered a crash with MapCache while testing my app.

Reproduction

  1. Make sure cache is at capacity (e.g. 100MB)
  2. Scroll the map constantly for 10 sec

Then controlCapacity function constantly delete files, which is expected. However, memory usage is growing quickly without pausing, eventually leading to a crash. It's easily reproducible.

Below is a screenshot.

Screenshot 2020-12-28 at 18 13 46

First peak did not lead to crash. It's because there are not enough new tiles flushing out old ones (i.e. did not scroll the map long enough). Second peak crashed.

quinncnl avatar Dec 28 '20 17:12 quinncnl

I don't see that in my app. I guess you should check your code for cycles...

NickAtGit avatar Oct 11 '22 20:10 NickAtGit

I can confirm the observation of strongwillow. Same behaviour in my app.

A (not so nice) workaround for me is to clear the cache when I get a memory pressure warning from the OS. At least that seems to work.

Frank-Peter avatar Oct 18 '22 09:10 Frank-Peter

The problem lies in the excessive call to FileManager.default.contentsOfDirectory when the cache is full. DiskCache creates the ordered list of URLs in the cache over and over again for every tile to throw out. It would be better to create such a list at startup and keep it up to date during all operations. I've done that experimentally it it works quite nicely. If anybody is interested, let me know.

Frank-Peter avatar Nov 02 '22 08:11 Frank-Peter