Skip to content

Memory leakage #25

Description

@sadeghte

When you run this simple code, memory grows unbounded. In my test it leaked more than 5 GB of memory.

import createKeccakHash from 'keccak'

const hash = msg => {
  return '0x' + createKeccakHash('keccak256').update(msg).digest('hex')
}

const mine = function(seed, difficulty = 5) {
  let nonce = 0;
  difficulty = parseInt(difficulty);
  const prefix = '0x' + new Array(difficulty).fill('0').join('')
  while (true) {
    const h = hash(seed + nonce);
    if (!!h && h.substring(0, difficulty+2) === prefix) {
      return nonce;
    }
    nonce += 1;
  }
}

console.log("running ....")
const seed = "hfjshjdhsjhdjshdjs"
const nonce = mine(seed, 8)
console.log({
  nonce,
})

the createKeccakHash method thakes some memory and not release it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions