Skip to content

Commit

Permalink
add dealloc of iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 13, 2023
1 parent 7428d78 commit 36bd9b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class NativeInstrumentProfileCollector {
var profiles = [InstrumentProfile]()
let listener: AnyObject = bridge(ptr: context)
if let listener = listener as? WeakListener {
let iterator = NativeProfileIterator(nativeProfiles)
let iterator = NativeProfileIterator(nativeProfiles, isDeallocated: false)

while (try? iterator.hasNext()) ?? false {
do {
Expand Down Expand Up @@ -109,7 +109,7 @@ public class NativeInstrumentProfileCollector {
func view() throws -> NativeProfileIterator {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread, dxfg_InstrumentProfileCollector_view(thread, collector))
return NativeProfileIterator(native)
return NativeProfileIterator(native, isDeallocated: true)
}

func setExecutor(_ executor: NativeExecutor) throws -> Bool {
Expand Down
8 changes: 7 additions & 1 deletion DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import Foundation
/// The location of the imported functions is in the header files "dxfg_ipf.h".
class NativeProfileIterator {
private let iterator: UnsafeMutablePointer<dxfg_iterable_ip_t>
private let isDeallocatd: Bool
let mapper = InstrumentProfileMapper()

deinit {
if isDeallocatd {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(iterator.pointee.handler)))
}
}

init(_ iterator: UnsafeMutablePointer<dxfg_iterable_ip_t>) {
init(_ iterator: UnsafeMutablePointer<dxfg_iterable_ip_t>, isDeallocated: Bool) {
self.isDeallocatd = isDeallocated
self.iterator = iterator
}

Expand Down

0 comments on commit 36bd9b8

Please sign in to comment.