-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1130 from ably/fix/1129-memory-leaks
Real time client memory leaks fixes
- Loading branch information
Showing
9 changed files
with
136 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
#include <asl.h> | ||
#include "NSObject+TestSuite.h" | ||
#include "ARTGCD.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// GCDTest.swift | ||
// Ably | ||
// | ||
// Created by Mikey on 12/01/2021. | ||
// Copyright © 2021 Ably. All rights reserved. | ||
// | ||
import XCTest | ||
|
||
class GCDTest: XCTestCase { | ||
func testScheduledBlockHandleDerefsBlockAfterInvoke() { | ||
let invokedExpectation = self.expectation(description: "scheduled block invoked") | ||
|
||
// retain counter: 1 | ||
var object = NSObject() | ||
|
||
// store reference for above weakified | ||
weak var weakObject = object | ||
|
||
// prepare schedule block | ||
var scheduledBlock = artDispatchScheduled(0, .main) { [object] in | ||
// retain counter +1 -> sum: 2 | ||
_ = object | ||
invokedExpectation.fulfill() | ||
} | ||
|
||
// invoke block | ||
_ = scheduledBlock | ||
|
||
waitForExpectations(timeout: 2, handler: nil) | ||
|
||
// destroy block reference | ||
// `object` retain counter -1, sum: 1 | ||
scheduledBlock = nil | ||
|
||
// assign new object to old variable | ||
// at this point old `object` should be destroyed, retain counter: -1, sum: 0 -> Destroy | ||
object = NSObject() | ||
|
||
// check if old `object` reference was destroyed | ||
XCTAssertNil(weakObject) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters