Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak on EmojiPicker #17

Open
fikricanc opened this issue May 7, 2023 · 9 comments
Open

Memory Leak on EmojiPicker #17

fikricanc opened this issue May 7, 2023 · 9 comments

Comments

@fikricanc
Copy link

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!

@Finalet
Copy link
Owner

Finalet commented May 8, 2023

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.

@fikricanc
Copy link
Author

fikricanc commented May 9, 2023

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!

@Finalet
Copy link
Owner

Finalet commented May 9, 2023

Thanks, any help is appreciated!

@loongman
Copy link
Contributor

loongman commented May 29, 2023

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

@Finalet
Copy link
Owner

Finalet commented May 29, 2023

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

@loongman
Copy link
Contributor

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

@loongman
Copy link
Contributor

loongman commented Jun 3, 2023

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

@zizicici
Copy link

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

@loongman
Copy link
Contributor

Good finding. @zizicici

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants