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 iOS: FastImage not released from memory when callbacks onLoad is set #398

Closed
wants to merge 4 commits into from

Conversation

StevenMasini
Copy link

@StevenMasini StevenMasini commented Jan 29, 2019

Changelog

Solution to the open issue #371

  • Use a weak reference to self to call sendOnLoad in the sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:

Holding a strong reference to self in a block can lead to memory leaks as the block will hold the reference until it is called.

Always pass weak reference of self into block in ARC?

@adammcarth
Copy link

I seem to be getting two compile errors in XCode when running these changes:

  1. Implicit conversion of an Objective-C pointer to 'FFFastImageView *const __weak *' is disallowed with ARC.
__weak typeof(self) *weakSelf = self;
  1. Bad receiver type 'FFFastImageView *const __weak *'.
[weakSelf sendOnLoad:image];

@StevenMasini
Copy link
Author

@adammcarth Okay I will have a look at it. Sound weird tho, you are not supposed to pass a strong pointer into a block.

@marf
Copy link

marf commented Feb 5, 2019

I seem to be getting two compile errors in XCode when running these changes:

  1. Implicit conversion of an Objective-C pointer to 'FFFastImageView *const __weak *' is disallowed with ARC.
__weak typeof(self) *weakSelf = self;
  1. Bad receiver type 'FFFastImageView *const __weak *'.
[weakSelf sendOnLoad:image];

Hello @adammcarth I have the same problem trying to applying the fix.
What should we do?

Thank you,
Marco

@marf
Copy link

marf commented Feb 5, 2019

I have tried also to change from __weak typeof(self) *weakSelf = self; to __weak FFFastImageView *weakSelf = self; and it compiles but the problem of the memory leak does not disappear.

@StevenMasini
Copy link
Author

StevenMasini commented Feb 20, 2019

Yeah sorry guys my bad, the correct syntax is __weak typeof(self) weakSelf = self;. It's been a while since I wrote Objective C, I forgot that typeof(self) will already define the type as a pointer. So no need *.

But still this fix isn't enough to fix the memory leaks.

…tImageView as it is the native side that will call the callback and not the js side
@StevenMasini
Copy link
Author

StevenMasini commented Feb 20, 2019

Well okay I am stupid, I have been chasing a ghost 😓

Actually if you implement onLoadStart, onError or onLoadEnd and you try to retrieve a parameter from it. Then you will end up with a huge memory leak.

I was trying to retrieve error from onError, but actually the native part doesn't return it at all.

Well at least I have discovered that you can't retrieve a parameter that doesn't exist from a callback.

Anyway we still need to give a weak pointer of self to the completion block of SDWebImage.

@marf
Copy link

marf commented Feb 24, 2019

Hello, @StevenMasini and thank you.
So has this change fixed the memory leaks?

Also changing from RTCBubblingEventBlock to RTCDirectEventBlock fixes the fact of the parameters to the callback which may generate memory leaks?

Thank you,
Marco

@StevenMasini
Copy link
Author

StevenMasini commented Mar 20, 2019

I am preparing another Pull Request with more fixes. I am closing this Pull Request as the new Pull Request will contain these fixes and more.

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

Successfully merging this pull request may close these issues.

None yet

3 participants