Skip to content

Commit

Permalink
Explicitly drop parser in order to free memory
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisalexander committed Feb 28, 2022
1 parent 3061047 commit 73cecc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions readstat/src/rs_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ impl ReadStatData {

// setup parser
// once call parse_sas7bdat, iteration begins
let error = ReadStatParser::new()
let mut parser = ReadStatParser::new()
// do not set metadata handler nor variable handler as already processed
.set_value_handler(Some(cb::handle_value))?
.set_row_limit(Some(self.batch_rows_to_process.try_into().unwrap()))?
.set_row_offset(Some(self.batch_row_start.try_into().unwrap()))?
.parse_sas7bdat(ppath, ctx);
.set_row_offset(Some(self.batch_row_start.try_into().unwrap()))?;

let error = parser.parse_sas7bdat(ppath, ctx);

// drop parser after finished
drop(parser);

match FromPrimitive::from_i32(error as i32) {
Some(ReadStatError::READSTAT_OK) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion readstat/src/rs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ReadStatParser {
}

pub fn parse_sas7bdat(
self,
&mut self,
path: *const c_char,
user_ctx: *mut c_void,
) -> readstat_sys::readstat_error_t {
Expand Down

0 comments on commit 73cecc8

Please sign in to comment.