Code Monkey home page Code Monkey logo

Comments (4)

ghowen avatar ghowen commented on July 17, 2024

It seems that changing line 35 in AEXML.swift to

private(set) weak var parent: AEXMLElement?

"fixes" the memory leak.

But this is not a clean solution, since now a parent object can become nil even if it has children. The parent reference in AEXMLElement should rather be an unowned reference, but then the parent cannot be optional and the code would have to be refactored accordingly.

I am stil rereading again and againt the chapter about ARC in the Apple Swift Book myself ;)

from aexml.

tadija avatar tadija commented on July 17, 2024

Hello,

first of all, thanks for the feedback, it's a good one.
I did some testing with your example, and it's behaving as you said.

parent property on AEXMLElement is optional by design, because AEXMLDocument (inherited from AEXMLElement) has no parent (it's parent property is set to nil on initialization).
Because of that I believe that solution you recommended (weak reference for parent property) is a way to go, because it will resolve strong reference cycle between AEXMLElement and parent (also AEXMLElement), but it will also allow parent to be nil when it needs to (AEXMLDocument).

If you want, you can send me a pull request with this fix, or I'll do it later.

Cheers,
// T

from aexml.

ghowen avatar ghowen commented on July 17, 2024

Just made my first pull request. Yay! ;) Please see comment in the request.
Thank you for AEXML and best regards, Georg

from aexml.

tadija avatar tadija commented on July 17, 2024

I'm glad you did. :)

I'll close this issue now, because it has been fixed via this pull request.

Cheers,
// T

from aexml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.