Skip to content

Commit 50d5e5b

Browse files
author
Louis Fréneau
committed
Improved memory management
- Early deallocation for Frame members - Early reset of shared pointers - Impact visible with heaptrack
1 parent 8d7a810 commit 50d5e5b

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

src/app/uvgVPCCencAppExample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int main(const int argc, const char* const argv[]) {
362362
uvgvpcc_enc::Logger::log(uvgvpcc_enc::LogLevel::INFO, "APPLICATION", "Encoded " + std::to_string(frameRead) + " frames.\n");
363363

364364
inputTh.join();
365-
uvgvpcc_enc::API::stopEncoder();
365+
// uvgvpcc_enc::API::stopEncoder(); // lf: not usefull (call two times ThreadQueue::stop()) because of custom destructor for ThreadQueue
366366

367367
if (uvgvpcc_enc::p_->timerLog) {
368368
encodingTimerTotal = uvgvpcc_enc::global_timer.elapsed() - encodingTimerTotal;

src/lib/bitstreamGeneration/atlas_context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <cstdint>
4141
#include <iostream>
4242
#include <memory>
43+
#include <vector>
4344

4445
#include "atlas_frame.hpp"
4546
#include "bitstream_common.hpp"
@@ -152,6 +153,10 @@ atlas_tile_data_unit atlas_context::create_atlas_tile_data_unit(const uvgvpcc_en
152153
}
153154
atdu.patch_information_data_.push_back(pid);
154155
}
156+
157+
158+
std::vector<uvgvpcc_enc::Patch>().swap(frameUVG->patchList); // Release memory
159+
155160
// Last patch is I_END patch
156161
patch_information_data end_patch;
157162
end_patch.patchMode = ATDU_PATCH_MODE_I_TILE::I_END;

src/lib/bitstreamGeneration/bitstreamGeneration.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ void BitstreamGeneration::createV3CGOFBitstream(const std::shared_ptr<uvgvpcc_en
6868
auto atlas = std::make_unique<atlas_context>();
6969
atlas->initialize_atlas_context(gofUVG, paramUVG);
7070

71+
72+
for(auto& frame : gofUVG->frames) {
73+
frame.reset(); // Release memory
74+
}
75+
7176
// --------------- Fetch video sub-bitstream data ---------------------------------------------
7277
// Occupancy map
7378
auto bitstream_ovd = std::make_unique<std::vector<uint8_t>>();
@@ -77,6 +82,7 @@ void BitstreamGeneration::createV3CGOFBitstream(const std::shared_ptr<uvgvpcc_en
7782
// }
7883
*bitstream_ovd.get() = gofUVG->bitstreamOccupancy;
7984
byteStreamToSampleStream(*bitstream_ovd.get(), 4, ovd_nals, false);
85+
std::vector<uint8_t>().swap(gofUVG->bitstreamOccupancy); // Release memory
8086

8187
// Geometry map
8288
auto bitstream_gvd = std::make_unique<std::vector<uint8_t>>();
@@ -86,6 +92,7 @@ void BitstreamGeneration::createV3CGOFBitstream(const std::shared_ptr<uvgvpcc_en
8692
// }
8793
*bitstream_gvd.get() = gofUVG->bitstreamGeometry;
8894
byteStreamToSampleStream(*bitstream_gvd.get(), 4, gvd_nals, false);
95+
std::vector<uint8_t>().swap(gofUVG->bitstreamGeometry); // Release memory
8996

9097
// Attribute map
9198
auto bitstream_avd = std::make_unique<std::vector<uint8_t>>();
@@ -95,6 +102,7 @@ void BitstreamGeneration::createV3CGOFBitstream(const std::shared_ptr<uvgvpcc_en
95102
// }
96103
*bitstream_avd.get() = gofUVG->bitstreamAttribute;
97104
byteStreamToSampleStream(*bitstream_avd.get(), 4, avd_nals, false);
105+
std::vector<uint8_t>().swap(gofUVG->bitstreamAttribute); // Release memory
98106

99107
// --------------- Calculate V3C unit size precision -------------------------------------------
100108
size_t v3c_max_size = v3c_parameter_set.get()->get_vps_byte_len();
@@ -132,5 +140,6 @@ void BitstreamGeneration::createV3CGOFBitstream(const std::shared_ptr<uvgvpcc_en
132140
} else {
133141
gof.write_v3c_chunk(output);
134142
}
143+
135144
output->available_chunks.release();
136145
}

src/lib/mapGeneration/mapGeneration.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,8 @@ void MapGenerationBaseLine::generateFrameMaps(const std::shared_ptr<uvgvpcc_enc:
556556

557557
// Geometry and attribute map generation //
558558
writePatches(frame, frame->mapHeight);
559-
560-
561-
559+
std::vector<Vector3<uint8_t>>().swap(frame->pointsAttribute); // Release memory
560+
562561
// Background filling //
563562
fillBackgroundImages(frame, frame->mapHeight);
564563

src/lib/patchGeneration/patchGeneration.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void PatchGeneration::generateFramePatches(std::shared_ptr<uvgvpcc_enc::Frame> f
115115
PPISegmenter ppiSegmenter(voxelizedPointsGeometry, pointsNormal);
116116
ppiSegmenter.initialSegmentation(voxelsPPIs, frame->frameId);
117117
ppiSegmenter.refineSegmentation(voxelsPPIs, frame->frameId);
118-
118+
119119
// "De-voxelization"
120120
std::vector<size_t> pointsPPIsBuffer;
121121
const std::vector<size_t>& pointsPPIs = useVoxelization ? pointsPPIsBuffer : voxelsPPIs;
@@ -134,4 +134,8 @@ void PatchGeneration::generateFramePatches(std::shared_ptr<uvgvpcc_enc::Frame> f
134134
std::sort(frame->patchList.begin(), frame->patchList.end(), [](const uvgvpcc_enc::Patch& patchA, const uvgvpcc_enc::Patch& patchB) {
135135
return std::max(patchA.widthInPixel_, patchA.heightInPixel_) > std::max(patchB.widthInPixel_, patchB.heightInPixel_);
136136
});
137+
138+
139+
std::vector<Vector3<typeGeometryInput>>().swap(frame->pointsGeometry); // Release memory
140+
137141
}

src/lib/patchGeneration/patchSegmentation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ void PatchSegmentation::patchSegmentation(const std::shared_ptr<uvgvpcc_enc::Fra
713713
refillRawPoints(resamplePointSet, rawPoints, frame->pointsGeometry, pointCount, flags, nnPropagationMapFlagTrue);
714714
}
715715

716+
std::vector<size_t>().swap(frame->patchPartition); // Release memory
717+
718+
716719
if (p_->exportIntermediatePointClouds) {
717720
const std::string plyFilePath =
718721
p_->intermediateFilesDir + "/patchSegmentation/PATCH-SEGMENTATION_f-" + uvgvpcc_enc::zeroPad(frame->frameId, 3) + ".ply";

0 commit comments

Comments
 (0)