Skip to content

Commit

Permalink
release memory after injesting a multi-buffer record
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Jul 2, 2022
1 parent 3c81052 commit 95b4733
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/parser/record_stream_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use nom::Err;
use nom::Needed::Size;
use nom::Needed::Unknown;

use crate::slurp::READ_BUFFER_SIZE;
use crossbeam_channel::{Receiver, Sender};
use std::thread;
use std::thread::JoinHandle;
Expand Down Expand Up @@ -87,8 +88,13 @@ impl HprofRecordStreamParser {
send_records
.send(next_pooled_vec)
.expect("channel should not be closed");
// parsing iteration complete without extra data needed
self.needed = 0;
if self.needed > 0 {
// Multi-buffer object successfully parsed
// Do not hold on too much working memory
self.loop_buffer.shrink_to(READ_BUFFER_SIZE * 2);
// Reset extra data needed flag
self.needed = 0;
}
}
Err(Err::Incomplete(Size(n))) => {
if self.debug_mode {
Expand Down

0 comments on commit 95b4733

Please sign in to comment.