-
Notifications
You must be signed in to change notification settings - Fork 124
/
object_lifetime.js
85 lines (68 loc) · 2.15 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
var gdal = require('../lib/gdal.js');
var assert = require('chai').assert;
var path = require('path');
describe('object cache', function() {
it('should return same object if pointer is same', function() {
for (var i = 0; i < 10; i++) {
gdal.log('Object Cache test run #' + i);
var ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1);
var band1 = ds.bands.get(1);
var 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', function() {
it('datasets should stay alive until all bands go out of scope', function() {
var ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1);
var band = ds.bands.get(1);
var ds_uid = ds._uid;
var 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', function() {
var ds = gdal.open('temp', 'w', 'MEM', 4, 4, 1);
var band = ds.bands.get(1);
var ds_uid = ds._uid;
var 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', function() {
var ds = gdal.open(path.join(__dirname, 'data/shp/sample.shp'));
var layer = ds.layers.get(0);
var ds_uid = ds._uid;
var 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', function() {
var ds = gdal.open(path.join(__dirname, 'data/shp/sample.shp'));
var layer = ds.layers.get(0);
var ds_uid = ds._uid;
var layer_uid = layer._uid;
layer = null;
gc();
assert.isTrue(gdal._isAlive(ds_uid));
assert.isFalse(gdal._isAlive(layer_uid));
});
});