react-native-fast-image: Memory Leak on iOS: FastImage not released from memory when callbacks onLoad is set

An engineer at my company noticed a memory leak on iOS when the props onLoad is set on iOS. FastImage doesn’t get released when it should be.

After investigating the source code, I found out that using a strong reference to self to call sendOnLoad in sd_setImageWithURL.

I suspect this line to be the cause of this memory leaks.

https://github.com/DylanVann/react-native-fast-image/blob/141a4a02931ba9e02ee169ba4543e77d924b6a79/ios/FastImage/FFFastImageView.m#L167

I can submit a Pull Request to transform this strong reference into a weak reference, which should fix the memory leak.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 17 (8 by maintainers)

Most upvoted comments

I would be happy if people could try my PR #433. It should fix the memory leak on iOS.

Let me know if it works for you or not ?

@truongluong1314520 You can set the onError but just don’t try to get any parameters from it.

onError don’t pass any parameters.

For instance do

onError={() => {
// your implemention
}}

but don’t

onError={error => {
// this will create a memory leak
// the same for every callback who doesn't pass parameters, just strictly follow the documentation
// don't try to retrieve parameters who doesn't exist
console.log(error)
}}