-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathobject_lifetime.js
85 lines (68 loc) · 2.2 KB
/
object_lifetime.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const gdal = require('../lib/gdal.js')
const assert = require('chai').assert
const path = require('path')
describe('object cache', () => {
it('should return same object if pointer is same', () => {
for (let i = 0; i < 10; i++) {
gdal.log(`Object Cache test run #${i}`)
const ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1)
const band1 = ds.bands.get(1)
const band2 = ds.bands.get(1)
assert.instanceOf(band1, gdal.RasterBand)
assert.equal(band1, band2)
assert.equal(band1.size.x, 4)
assert.equal(band2.size.x, 4)
gc()
}
})
})
describe('object lifetimes', () => {
it('datasets should stay alive until all bands go out of scope', () => {
let ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1)
let band = ds.bands.get(1)
const ds_uid = ds._uid
const band_uid = band._uid
ds = null
gc()
assert.isTrue(gdal._isAlive(ds_uid))
assert.isTrue(gdal._isAlive(band_uid))
band = null
gc()
assert.isFalse(gdal._isAlive(ds_uid))
assert.isFalse(gdal._isAlive(band_uid))
})
it('bands should immediately be garbage collected as they go out of scope', () => {
const ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1)
let band = ds.bands.get(1)
const ds_uid = ds._uid
const band_uid = band._uid
band = null
gc()
assert.isTrue(gdal._isAlive(ds_uid))
assert.isFalse(gdal._isAlive(band_uid))
})
it('datasets should stay alive until all layers go out of scope', () => {
let ds = gdal.open(path.join(__dirname, 'data/shp/sample.shp'))
let layer = ds.layers.get(0)
const ds_uid = ds._uid
const layer_uid = layer._uid
ds = null
gc()
assert.isTrue(gdal._isAlive(ds_uid))
assert.isTrue(gdal._isAlive(layer_uid))
layer = null
gc()
assert.isFalse(gdal._isAlive(ds_uid))
assert.isFalse(gdal._isAlive(layer_uid))
})
it('layers should immediately be garbage collected as they go out of scope', () => {
const ds = gdal.open(path.join(__dirname, 'data/shp/sample.shp'))
let layer = ds.layers.get(0)
const ds_uid = ds._uid
const layer_uid = layer._uid
layer = null
gc()
assert.isTrue(gdal._isAlive(ds_uid))
assert.isFalse(gdal._isAlive(layer_uid))
})
})