diff --git a/DXFeedFramework/Native/Ipf/Live/NativeInstrumentProfileCollector.swift b/DXFeedFramework/Native/Ipf/Live/NativeInstrumentProfileCollector.swift index 65f1967a1..3f854a91e 100644 --- a/DXFeedFramework/Native/Ipf/Live/NativeInstrumentProfileCollector.swift +++ b/DXFeedFramework/Native/Ipf/Live/NativeInstrumentProfileCollector.swift @@ -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 { @@ -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 { diff --git a/DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift b/DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift index 66fcf158d..11bd50c1e 100644 --- a/DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift +++ b/DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift @@ -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 + 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) { + init(_ iterator: UnsafeMutablePointer, isDeallocated: Bool) { + self.isDeallocatd = isDeallocated self.iterator = iterator }