forked from parmanoir/jscocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11 retain test 2.js
49 lines (28 loc) · 1.18 KB
/
11 retain test 2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Check JS's GC destroys objc instances
*/
// JSCocoaController.garbageCollect
// Cannot be tested in one thread as ObjC GC has no way of blocking the main thread to collect everything
if (!hasObjCGC)
{
var newClass = JSCocoaController.createClass_parentClass("SomeRetainCountTest", "NSObject")
var count0 = JSCocoaController.liveInstanceCount(SomeRetainCountTest)
var o1 = newClass.alloc.init
o1.release
var o2 = newClass.instance
// log('o1=' + o1 + ' rc=' + o1.retainCount)
// log('o2=' + o2 + ' rc=' + o2.retainCount)
newClass.instance
// JSCocoaController.logInstanceStats
var count1 = JSCocoaController.liveInstanceCount(SomeRetainCountTest)
if (count1 != 3) throw 'invalid retain count - got ' + count1 + ', expected 3 (1)'
o1 = null
o2 = null
__jsc__.garbageCollect
// JSCocoaController.logInstanceStats
var count2 = JSCocoaController.liveInstanceCount(SomeRetainCountTest)
if (count2 != 0) throw 'invalid retain count - got ' + count2 + ', expected 0 (2)'
// JSCocoaController.log('***' + count0 + '***' + count1 + '***' + count2 + '***')
// JSCocoaController.logInstanceStats
newClass = o1 = o2 = count1 = count2 = null
}