mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
refactor!: use Finalizer
to automatically free allocated memory for objects (#48)
BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
parent
94c40f9a94
commit
a3213a88a2
103 changed files with 2278 additions and 2595 deletions
|
@ -5,10 +5,9 @@ import 'package:libgit2dart/src/bindings/revwalk.dart' as bindings;
|
|||
|
||||
class RevWalk {
|
||||
/// Initializes a new instance of the [RevWalk] class.
|
||||
///
|
||||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||
RevWalk(Repository repo) {
|
||||
_revWalkPointer = bindings.create(repo.pointer);
|
||||
_finalizer.attach(this, _revWalkPointer, detach: this);
|
||||
}
|
||||
|
||||
late final Pointer<git_revwalk> _revWalkPointer;
|
||||
|
@ -150,5 +149,14 @@ class RevWalk {
|
|||
void simplifyFirstParent() => bindings.simplifyFirstParent(_revWalkPointer);
|
||||
|
||||
/// Releases memory allocated for [RevWalk] object.
|
||||
void free() => bindings.free(_revWalkPointer);
|
||||
void free() {
|
||||
bindings.free(_revWalkPointer);
|
||||
_finalizer.detach(this);
|
||||
}
|
||||
}
|
||||
|
||||
// coverage:ignore-start
|
||||
final _finalizer = Finalizer<Pointer<git_revwalk>>(
|
||||
(pointer) => bindings.free(pointer),
|
||||
);
|
||||
// coverage:ignore-end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue