Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Memory leak when initializing CommonMark.Document via commonmark string #19

@fe9lix

Description

@fe9lix

Hi! I've noticed a memory leak when using CommonMark.Document "standalone" as root node, basically the first example that is given in the README file (just initialize a new Document with a commonmark string).
It seems that for this initializer the internal managed property would not be set to true, and then prevent the cmark nodes from being freed in deinit.
To fix that, I just added an extension that would set the managed property, sth. like this (I'm sure there are better ways...):

public extension Document {
  // Enforce managed flag to be set when the node is used "standalone", otherwise no freeing of cmark nodes will happen on deinit.
  class func root(_ commonmark: String, options: ParsingOptions = []) throws -> Document {
    let document = try Self.init(commonmark, options: options)
    document.managed = true
    return document
  }
}

Can you confirm this or am I missing sth. in terms of the API or intended usage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions