Skip to content

Memory leak when using nested Seq.unfold to generate first 1000000 primes #14818

Answered by mciccottidmg
chav-n asked this question in Q&A
Discussion options

You must be logged in to vote

I think the issue you're running into is that you're creating a lot of large, ephemeral memory allocations.

I ran your code in FSI with #time on and here are a few illustrative results:

10,000:

Real: 00:00:00.431, CPU: 00:00:00.546, GC gen0: 193, gen1: 1, gen2: 0

80,000:

Real: 00:00:39.248, CPU: 00:00:39.359, GC gen0: 12254, gen1: 83, gen2: 0

100,000:

Real: 00:01:09.639, CPU: 00:01:09.703, GC gen0: 19144, gen1: 14116, gen2: 1

As you can see, as your number of primes go up, the number of higher generational garbage collections increases, which means the lists allocated in previous iterations of your sequence become less and less likely to have been collected as later iterations are e…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@chav-n
Comment options

@Xyncgas
Comment options

Answer selected by chav-n
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #14758 on February 27, 2023 17:42.