Finalet/Elegant-Emoji-Picker

Memory Leak on EmojiPicker

fikricanc opened this issue · 9 comments

Hi,

First of all, thank you for creating this!

However, I have noticed a memory leak when using the library. EmojiPicker never gets released from memory.

You can reproduce this issue on Demo app.

Steps to reproduce:

  1. Present the emoji picker.
  2. Monitor the memory usage of the app.
  3. Dismiss the emoji picker.
  4. Monitor the memory usage of the app again.

image

Thanks in advance!

Hi!

Thank you for providing this. Its an annoying booboo that I'll dive deeper after my other projects. Hope its not game breaking for your app.

Thanks for responding! I'll try take a look at the source code and see if I can help identify the issue too. It's worth noting that I've also noticed similar memory leak problems in other emoji picker libraries.

I'll keep you updated on my findings.

Thanks again for your help!

Thanks, any help is appreciated!

I'd like to contribute. However, this is not doable for now, due to lack of permission.

To fix it, apply 'weak' to delegate property to avoid from reference cycle.

Could you please apply this small change to the main branch? Thanks. @Finalet

On ElegantEmojiPicker.swift

public var delegate: ElegantEmojiPickerDelegate?
->
public weak var delegate: ElegantEmojiPickerDelegate?

And on ElegantEmojiPickerDelegate.swift

public protocol ElegantEmojiPickerDelegate
->
public protocol ElegantEmojiPickerDelegate: AnyObject

Thanks for the input, I will look into it!

In terms of contributing:

However, this is not doable for now, due to lack of permission.

Are you unable to fork and create a pull request to the base repository? @loongman

As suggested, I have created a PR for this issue. @Finalet

The original issue should be fixed now.

However, found another quite interesting issue.

As you can see on the screen recording, after switch among different categories on the toolbar, memory increased rapidly, it stay there even after closed the picker.

After some quick investigations, it seems the OS generated huge cache(1000+ Malloc Blocks) for label.text = emoji.emoji on EmojiCell.swift. If simply replace that code line as label.text = "A", then, that behavior(1000+ Malloc Blocks) is no longer observable.

Any thoughts/suggestions on that? @Finalet

Screen.Recording.2023-06-03.at.21.53.53.mov
Screenshot 2023-06-03 at 21 46 30 Screenshot 2023-06-03 at 21 47 24

Have you tried switching the app to the background? I found that it seems to reduce memory usage to a reasonable level.

Good finding. @zizicici

Memory usage can also be reduced if apply 'Debug -> Simulate Memory Warning' to Simulator.