kip17 instance memory leak
Closed this issue · 3 comments
Describe the bug
kip17 instance memory leak
How to reproduce
node --expose-gc app.js
const Caver = require('caver-js');
const caver = new Caver('wss://api.baobab.klaytn.net:8652');
const klipAddress = '0xb26e09db6656b998d2913f13870e06c151c37900';
async function main() {
for (let i = 0; ; ++i) {
const kip = new caver.kct.kip17(klipAddress);
if ((i % 1000) === 0) {
if (global.gc) { global.gc() }
const used = process.memoryUsage().heapUsed / 1024 / 1024
console.log(`Heap used ${used}`)
}
}
}
main();
Heap used 11.133682250976562
Heap used 23.77117156982422
Heap used 36.463768005371094
Heap used 49.22425842285156
Heap used 61.97528076171875
Heap used 74.73260498046875
Heap used 87.46646118164062
Heap used 100.2000732421875
Heap used 112.9622802734375
Heap used 125.69624328613281
Heap used 138.43016815185547
memory increase.
node --expose-gc app.js
const Caver = require('caver-js');
let caver = new Caver('wss://api.baobab.klaytn.net:8652');
const klipAddress = '0xb26e09db6656b998d2913f13870e06c151c37900';
async function main() {
for (let i = 0; ; ++i) {
const kip = new caver.kct.kip17(klipAddress);
if ((i % 1000) === 0) {
caver.currentProvider.connection.close();
caver = new Caver('wss://api.baobab.klaytn.net:8652');
if (global.gc) { global.gc() }
const used = process.memoryUsage().heapUsed / 1024 / 1024
console.log(`Heap used ${used}`)
}
}
}
main();
Heap used 11.255668640136719
Heap used 23.70966339111328
Heap used 23.753334045410156
Heap used 23.766998291015625
Heap used 23.792816162109375
Heap used 23.808685302734375
Heap used 23.821487426757812
Heap used 23.82750701904297
Heap used 23.846923828125
Heap used 23.858047485351562
Heap used 23.86418914794922
Heap used 23.88085174560547
Heap used 23.891876220703125
Expected behavior
memory should not increase
Attachments
If applicable, add data, logs or screenshots to help explain your problem.
Environment (please complete the following information)
- caver-js version or git revision that exhibits the issue
- OS and its version [e.g. macOS/10.14]
"caver-js": "^1.6.4"
macOS/11.2.3 & ubuntu server 16.04
Additional context
web3 memory leak
maybe it's the same issue
"caver-js": "github:jimni1222/caver-js#leak"
Heap used 10.977645874023438
Heap used 11.086509704589844
Heap used 11.343368530273438
Heap used 11.596641540527344
Heap used 11.852760314941406
Heap used 12.117965698242188
Heap used 12.362602233886719
Heap used 12.608016967773438
Heap used 12.879783630371094
Heap used 13.124046325683594
Heap used 13.36865234375
Heap used 13.654243469238281
Heap used 13.898513793945312
Heap used 14.143424987792969
- close connection
Heap used 11.079086303710938
Heap used 11.0570068359375
Heap used 11.024040222167969
Heap used 11.057579040527344
Heap used 11.066177368164062
Heap used 11.083106994628906
Heap used 11.095451354980469
Heap used 11.101715087890625
Heap used 11.120864868164062
Heap used 11.132461547851562
Heap used 11.138374328613281
Heap used 11.155181884765625
Heap used 11.165817260742188
Heap used 11.171592712402344
Heap used 11.186790466308594
Heap used 11.196830749511719
Heap used 11.201332092285156
Heap used 11.216758728027344
Heap used 11.228240966796875
Why are the two results different?
Thank you, @jimni1222
The difference between the code above and the code below is whether or not to allocate a new instance to the caver.
If you simply want to close the websocket connection and restart it, you can use caver.currentProvider.reconnect
or caver.setProvider('url')
, and you can see that the results above and below are similar.
@block-tx-hash I released caver-js v1.6.5-rc.1. Please use this for now :) If there is another issue, feel free to let me know.