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

Added Memory Clean-up #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added Memory Clean-up #1

wants to merge 2 commits into from

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