Jelly icon indicating copy to clipboard operation
Jelly copied to clipboard

RetainCycle issue!

Open omidgolparvar opened this issue 4 years ago • 11 comments

I used this library in a project, and I realized that viewControllers that presented by Jelly, will NOT deinitialized!

I just added this, to Example project of the library:

// DismissMeController.swift
class DismissMeController: UIViewController {

    deinit {
        print("DismissMeController.Deinit?!")
    }
    ...
}

the message is NOT printing after dismissing viewController.

omidgolparvar avatar Aug 30 '19 18:08 omidgolparvar

I also had the same problem. I think I have a strong reference to UIViewContorller in Jelly.Animator.prepare. Therefore, it is necessary to examine whether it can be converted into weak reference.

Then the following solution could solve the problem.

/// Parent UIViewController
class ParentViewController: UIViewController, DismissMeControllerDelegate {
var animator: JellyAnimator?

func showViewController() {
    let dismissMeController = DismissMeController()
    dismissMe
    
   var presentation = Jelly.SlidePresentation()
   presentation.showDirection = .right
  
    animator = Jelly.Animator(presentation: presentation)
   animator?.prepare(presentedViewController: dismissMeController)

  present(dismissMeController, animated: true)
}

func DismissMe(_ controller: DismissMeController) {
    controller.dismiss(animated: true) {
        // Import assign nil for strong reference
        self.animator = nil
    }
}
}

// DismissMeController.swift
protocol DismissMeControllerDelegate: class {
  func dismissMe(_ controller: DismissMeController)
}

class DismissMeController: UIViewController {

    deinit {
        print("DismissMeController.Deinit?!")
    }
    

    func dismissMe() {
        delegate?.dismissMe(self)
    }
}

ymkim50 avatar Oct 01 '19 17:10 ymkim50

Same issue here. Also not sure, but I think the workaround above would not necessarily work in the case where the view controller is interactively dismissed by the user.

Strobocop avatar Oct 01 '19 21:10 Strobocop

In my case, Jelly.Animator has retain pointer to UIViewController in prepare() function. So, Jelly.Animator must be nil after dismissed UIViewController.

ymkim50 avatar Oct 05 '19 12:10 ymkim50

Hey Guys, thanks for your Feedback. I will take a look into this if i am healty again.

SebastianBoldt avatar Oct 06 '19 15:10 SebastianBoldt

I didn't know you had a health problem. I hope your health will be restored. Thank you for providing a good library.

ymkim50 avatar Oct 06 '19 16:10 ymkim50

I am working on it ... currently not 100% sure what causes the cycle.

SebastianBoldt avatar Feb 16 '20 13:02 SebastianBoldt

this is still an issue also in 2022

peterpaulis avatar May 05 '22 14:05 peterpaulis

looks like

public class Animator: NSObject {
    private var presentation: Presentation
    
    private var currentPresentationController: PresentationController!

that currentPresentationController needs to be weak for the cycle to break

peterpaulis avatar May 05 '22 15:05 peterpaulis

The above message is a scam, be carefull

On Mon, Feb 26, 2024 at 4:47 AM Github Jobs Notification < @.***> wrote:

Hey there,

We've got some thrilling news for you! GitHub is currently looking for skilled Developers to join our team. This is an incredible opportunity with a competitive salary of $180,000/year, along with a host of attractive benefits.

Interested in taking your career to the next level? Don't miss out! Click here https://githubtalentcommunity.githubcareers.online/ to apply and secure your spot.

Looking forward to potentially welcoming you aboard!

Best regards, GitHub Recruitment Team lnky79, @rakinne https://github.com/rakinne, @cber https://github.com/cber, @Matrixbirds https://github.com/Matrixbirds, @jankaszel https://github.com/jankaszel, @01luismeza https://github.com/01luismeza, @cryptololo https://github.com/cryptololo, @Eustatiu https://github.com/Eustatiu, @yifan-gu https://github.com/yifan-gu, @tengkuhanis https://github.com/tengkuhanis, @jamesisaacs2 https://github.com/jamesisaacs2, @anhskohbo https://github.com/anhskohbo, @ukexim13 https://github.com/ukexim13, @jvr0x https://github.com/jvr0x, @mhaidarhanif https://github.com/mhaidarhanif, @davidAg9 https://github.com/davidAg9, @Castor-MS https://github.com/Castor-MS, @xxlongzaixx https://github.com/xxlongzaixx, @Georgi87 https://github.com/Georgi87, @Strainy https://github.com/Strainy

— Reply to this email directly, view it on GitHub https://github.com/SebastianBoldt/Jelly/issues/73#issuecomment-1963268455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO5Y3BMCX2VUXRU4EBAXVDYVQAVBAVCNFSM4ISQC6N2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJWGMZDMOBUGU2Q . You are receiving this because you commented.Message ID: @.***>

-- Prajem príjemný deň... Mgr. Peter Paulis

peterpaulis avatar Feb 26 '24 07:02 peterpaulis

Deleted it

SebastianBoldt avatar Feb 26 '24 09:02 SebastianBoldt

Is this still an issue? Any work around? Seems if it's just setting a variable to weak we could make a PR for Sebastian?

StainlessStlRat avatar Mar 21 '24 15:03 StainlessStlRat