Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Memory leak for the fromWei utility function for stirng input #5515

@nazarhussain

Description

@nazarhussain

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

If the input value for the fromWei function is a string type, it leaks the memory and heap continuously increased.

Expected Behavior

There should not be a memory leak regardless of the type of input.

Steps to Reproduce

// test.js
const { fromWei } = require('web3-utils');

const limit = 2_000_000;

const toKb = num => (num / 1024).toFixed();

new Array(limit).fill('10000').forEach((d, i) => {
	if (i % 10000 === 0) {
		const mem = process.memoryUsage();
		console.log(`heap: ${toKb(mem.heapUsed)}, total: ${toKb(mem.heapTotal)} rss: ${toKb(mem.rss)}`);
	}
	fromWei(d, 'ether');
});

Start the node process with following options.

NODE_OPTIONS=--max-old-space-size=500 node test.js

Web3.js Version

4.x

Environment

  • Operating System: Mac/Linux
  • Node.js Version: 16.6
  • NPM Version: 8.11

Anything Else?

This behaviour was not seen with the 1.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAddressing a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions