-
Notifications
You must be signed in to change notification settings - Fork 2
[#125] Ensuring objects are deleted properly #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
angeloprobst
merged 24 commits into
master
from
angelo/#125/fixing-memory-leaks--adding-deletions
Mar 24, 2025
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
15d2a75
deleting several objects on destructors, but still seeing memory usag…
angeloprobst ab63128
TODO comments updated
angeloprobst a9bb947
removed unneeded commented line
angeloprobst 09cdfe5
reverting format
angeloprobst 710138c
reverting format
angeloprobst eeb1bea
reverting format
angeloprobst d8c8a9f
Making Iterator delete precedent
angeloprobst 9befbd4
adding default deleter to shared_ptr<char> variables
angeloprobst 12db176
fixing most relevant leaks
angeloprobst 35641cc
Merge branch 'master' into angelo/#125/fixing-memory-leaks--adding-de…
angeloprobst ecb80db
re-enabling BUILD_WHEELS
angeloprobst 6dd4d59
Merge remote-tracking branch 'origin/master' into angelo/#125/fixing-…
angeloprobst dc013bb
removing unnecessary copy
angeloprobst 707f0bd
Merge branch 'master' into angelo/#125/fixing-memory-leaks--adding-de…
angeloprobst aafe3a5
small fixes while checking why link_creation_agent_test is failling
angeloprobst a00eed5
process explodes if it is forcibly terminated while a sleep is running
angeloprobst 86614ee
progress on tests
angeloprobst f0b6be2
tests working
angeloprobst 5958e72
adding/removing some comments/logs
angeloprobst bf669b7
Merge branch 'master' into angelo/#125/fixing-memory-leaks--adding-de…
angeloprobst 259cf01
commenting out docker run to build evolution
angeloprobst 448f235
Merge branch 'master' into angelo/#125/fixing-memory-leaks--adding-de…
angeloprobst 9284001
binding host env vars into build container
angeloprobst 8fa1b4c
skipping test_das_node.py
angeloprobst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <mutex> | ||
#include <thread> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
#include "commons/Utils.h" | ||
|
||
using namespace std; | ||
|
||
namespace query_engine { | ||
|
||
class Worker { | ||
public: | ||
virtual bool is_work_done() = 0; | ||
}; | ||
|
||
template <class T, typename enable_if<is_base_of<Worker, T>::value, bool>::type = true> | ||
class LazyWorkerDeleter { | ||
public: | ||
LazyWorkerDeleter() | ||
: shutting_down_flag(false), | ||
objects_deleter_thread(make_unique<thread>(&LazyWorkerDeleter::objects_deleter_method, this)) { | ||
} | ||
|
||
~LazyWorkerDeleter() { | ||
if (this->shutting_down_flag) return; | ||
this->shutting_down_flag = true; | ||
this->objects_deleter_thread->join(); | ||
this->objects_deleter_thread.reset(); | ||
lock_guard<mutex> lock(this->objects_mutex); | ||
T* obj; | ||
while (!this->objects.empty()) { | ||
obj = this->objects.front(); | ||
this->objects.erase(this->objects.begin()); | ||
delete obj; | ||
} | ||
} | ||
|
||
void add(T* obj) { | ||
lock_guard<mutex> lock(this->objects_mutex); | ||
if (!this->shutting_down_flag) this->objects.push_back(obj); | ||
} | ||
|
||
private: | ||
vector<T*> objects; | ||
mutex objects_mutex; | ||
bool shutting_down_flag; | ||
unique_ptr<thread> objects_deleter_thread; | ||
|
||
void objects_deleter_method() { | ||
T* obj; | ||
while (!this->shutting_down_flag) { | ||
{ | ||
lock_guard<mutex> lock(this->objects_mutex); | ||
while (!this->objects.empty()) { | ||
obj = this->objects.front(); | ||
if (obj->is_work_done()) { | ||
this->objects.erase(this->objects.begin()); | ||
delete obj; | ||
} | ||
} | ||
} | ||
commons::Utils::sleep(5000); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace query_engine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.