telerik / mobile-cli-lib

Contains common infrastructure for CLIs - mainly AppBuilder, NativeScript, DDB and Proton.
Apache License 2.0
11 stars 10 forks source link

Fix leaking handlers for iOS device logs #1022

Closed rosen-vladimirov closed 6 years ago

rosen-vladimirov commented 6 years ago

In case iOS Device is detached, the IOSDevice instance is kept alive. The reason is the handler for device logs, that IOSDevice passes to iOSDeviceOperations. As iOSDeviceOperations is still alive, the IOSDevice instance is also alive. Reattaching the same device will cause duplicate logs. Detaching and attaching it again will lead to additional logs.

In order to fix the issue, convert iOSDeviceOpertations to event emitter and emit event when there's data for logging. Each IOSDevice will add handler for the event and will do its logic. In case device is detached (i.e. DeviceLost event is fired in DevicesService), call a newly added method to the specific IDevice instance. It's purpose is to clean the used resource. For iOS device, this method will remove the handler for devceLogData event of iOSDeviceOperations.