From 867b5772f63795d220ad0f9fa8986c68e8042146 Mon Sep 17 00:00:00 2001 From: xuchuanyin Date: Tue, 14 Dec 2021 22:32:24 +0800 Subject: [PATCH] clear memory of sample data right after BinMapper is constructed to save memory Sample data is useless after BinMapper is constructed, but the corresponding memory is still there before feature extraction is finished. --- src/io/dataset_loader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/io/dataset_loader.cpp b/src/io/dataset_loader.cpp index 1beff696f904..5ab6572b14b9 100644 --- a/src/io/dataset_loader.cpp +++ b/src/io/dataset_loader.cpp @@ -234,8 +234,9 @@ Dataset* DatasetLoader::LoadFromFile(const char* filename, int rank, int num_mac auto sample_data = SampleTextDataFromMemory(text_data); CheckSampleSize(sample_data.size(), static_cast(dataset->num_data_)); - // construct feature bin mappers + // construct feature bin mappers & clear sample data ConstructBinMappersFromTextData(rank, num_machines, sample_data, parser.get(), dataset.get()); + std::vector().swap(sample_data); if (dataset->has_raw()) { dataset->ResizeRaw(dataset->num_data_); } @@ -254,8 +255,9 @@ Dataset* DatasetLoader::LoadFromFile(const char* filename, int rank, int num_mac } CheckSampleSize(sample_data.size(), static_cast(dataset->num_data_)); - // construct feature bin mappers + // construct feature bin mappers & clear sample data ConstructBinMappersFromTextData(rank, num_machines, sample_data, parser.get(), dataset.get()); + std::vector().swap(sample_data); if (dataset->has_raw()) { dataset->ResizeRaw(dataset->num_data_); }