Skip to content

Conversation

@jgleesawn
Copy link

Added a cascading memory clean-up effect based on panics caused by writing to closed channels.
Usage:
primes := Sieve()
close(primes)
This allows you to create multiple fast prime-number generators without suffering from massive memory problems.
Thanks for writing this in the first place.

Added .Close() methods to PeekCh and PeekChHeap
Combining these with close(channel) A cascading closing effect can be
utilized to clean up memory.
primes := Sieve() Gives you a prime number generator.
close(primes)  Starts the cascading effect that cleans the memory.
@aht
Copy link
Owner

aht commented Aug 8, 2014

sorry for late response, for some reason I didn't see this coming thru my email.

I wrote this as a toy example to play with goroutines and didn't quite envision this to be used in production, mainly due to the fact that it spawns a lot of goroutines. I'm sure there are better ways to generate prime faster with lower memory usage!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants