Skip to content

Commit

Permalink
Fix lifetime issues with Swift 5.10
Browse files Browse the repository at this point in the history
A more robust fix is to use Unmanaged and insert retain / release. But
this fix would avoid extra retain / release.
  • Loading branch information
liuliu committed Mar 28, 2024
1 parent 048d733 commit c58c4f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nnc/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ extension Model {
_inputs, Int32(inputs.count), _outputs, Int32(outputs.count),
trainable == true ? 1 : (trainable == false ? 0 : -1), name)!
self.init(cModel)
// Extending the lifetime of the inputs / outputs until self.init is done.
withExtendedLifetime((inputs, outputs)) {}
}

/**
Expand All @@ -294,6 +296,8 @@ extension Model {
let cModel = ccv_cnnp_sequential_new(
_models, Int32(models.count), trainable == true ? 1 : (trainable == false ? 0 : -1), name)!
self.init(cModel)
// Extending the lifetime of the input until self.init is done.
withExtendedLifetime(models) {}
}

}
Expand Down

0 comments on commit c58c4f7

Please sign in to comment.