Closed GoogleCodeExporter closed 9 years ago
I think this may just be the fact that the GC is taking a while to run. Could
you try the following:
http://play.golang.org/p/a3SEI3UInn
If that shows a lot of memory before the GC and little memory after, then it's
not a memory leak, just a bad use of the GC.
If you look at
https://code.google.com/p/gopacket/source/browse/pfring/pfring.go#134, you'll
notice that whenever we issue a call to PFRing, we alloc a buffer of size
snaplen. Most of that isn't used, hence there's a good chance we over-use
memory, especially with high snaplens. We could optimize this a bit (create a
buffer that's N*snaplen, and just return pieces of it), but that could lead to
other problems (keeping one packet around means big buffer stuck in memory and
un-GC-able).
You can avoid memory issues using pfring's ReadPacketDataTo or
ZeroCopyReadPacketData functions to not allocate a buffer every time a packet
is read in. That means passing the data into gopacket.NewPacket yourself, but
the upsides are pretty big :)
Read the docs on ZeroCopyPacketData carefully if you decide to go that route,
it can be finicky ;)
Original comment by gconnell@google.com
on 23 Jun 2014 at 9:01
I'm going to mark as WontFix right now, but feel free to push back if you find
this is actually a memory leak, or if you think there's other things we could
do to make this better.
Original comment by gconnell@google.com
on 25 Jun 2014 at 9:37
Original issue reported on code.google.com by
pavel.odintsov
on 23 Jun 2014 at 8:50