AlexandrGraschenkov / TelegramChart

Telegram iOS Chart Competition 2019, (4'th place)
21 stars 4 forks source link

View Couldn’t be dismissed #1

Open jiminghe opened 3 years ago

jiminghe commented 3 years ago

Hi,

Thanks for designing this incredible chart! I was using it to plot data at 60 Hz, it works well. I designed several views and when I tried to segue back to the previous view, I found that the memory doesn't decrease and when I try to get into the chart view again, the memory increased by 50MB again, and this happens again and again, so the memory was piling up each time I run the chart view.

I had tried to look into it and it seems that we need to "autoreleasepool" for the chart draw/render.

But I don't know where to change your code.

Could you please kindly help yo take a look at this?

Thanks

AlexandrGraschenkov commented 3 years ago

Hi Got you. I will try to find some time in next few days to look at.

For now I only can recommend print something in deinit call for potential leak objects. Also Instruments can help to you. 50mb it's pretty large chunk of data.

jiminghe commented 3 years ago

Hi Alex,

I have done some searching, a lot of people say the CADisplayLink needs to be manually invalidated. If I created a ChartView object like let chart = ChartView(), how can I invalidated displaylink in the ViewDidDisappear?

https://stackoverflow.com/questions/47368609/definitively-do-you-have-to-invalidate-a-cadisplaylink-when-the-controller-di https://stackoverflow.com/questions/59440342/cametallayer-nextdrawable-memory-leak http://openradar.appspot.com/23977735

Thanks!

AlexandrGraschenkov commented 3 years ago

CADIsplayLink used only inside DisplayLinkAnimator. If you just call closure with CGFloat(1) and don't run DisplayLink animation, then problem still occurs.

Yesterday I dig inside this problem. Found that ChartCopmosedView is deleting fine, but ChartView don't want to release. It's really not trivial to uderstand where we have strong reference. Looks like some system object from Metal get strong pointer to our classes.