Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re: memory leak when calling re proc repeatedly #11139

Jjp137 opened this issue Apr 29, 2019 · 1 comment


None yet
4 participants
Copy link

commented Apr 29, 2019

When calling the re proc repeatedly, as shown in the examples below, memory usage increases continuously.

Yes, it may be better not to do this, but it's easy to casually specify a regular expression literal as an argument to the various procs within the re module, so the memory leak can be surprising.


import re

while true:  # Stop with Ctrl+C
  discard findAll("", re"[a-z]")

...and also:

import re

proc test() =
  let regex = re"[a-z]"
  discard findAll("", regex)

while true:  # Stop with Ctrl+C


Declaring the regex outside any loops entirely, such as within a global variable, and then using that instead does not noticeably leak memory, such as in this example:

import re

let regex = re"[a-z]"

while true:
  discard findAll("", regex)

Additional Information

Output of nim -v:

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-04-28
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 55aa2129b5b32c0bb9862c66d3ebbd681f727274
active boot switches: -d:release

Also occurs with 0.19.4.


This comment has been minimized.

Copy link

commented May 15, 2019

Workaround: import nre instead, no memory leaks for the two original leaking examples.

narimiran added a commit to narimiran/Nim that referenced this issue May 16, 2019

fix nim-lang#11139 (re.nim memory leak)
Use the same PCRE function for freeing up the memory as nre.nim does.

@Araq Araq closed this in 9d4190a May 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.