Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
dvtate committed Dec 15, 2023
1 parent 4cf5880 commit f9cef94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions vm/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void GarbageCollector::sweep() {
else if (*u == GarbageCollector::UsageColor::GREY)
*u = GarbageCollector::UsageColor::WHITE;
}
for (auto* ptr : this->_heap_nfc) {
auto* u = (GarbageCollector::UsageColor*) (((char*) ptr) - 1);
if (*u == GarbageCollector::UsageColor::WHITE)
destroy(ptr);
else if (*u == GarbageCollector::UsageColor::GREY)
*u = GarbageCollector::UsageColor::WHITE;
}
for (auto* ptr : this->_heap_lamret) {
auto* u = (GarbageCollector::UsageColor*) (((char*) ptr) - 1);
if (*u == GarbageCollector::UsageColor::WHITE)
Expand Down Expand Up @@ -91,6 +98,7 @@ void GarbageCollector::sweep() {
+ this->_heap_list.size()
+ this->_heap_obj.size()
+ this->_heap_nfn.size()
+ this->_heap_nfc.size()
+ this->_heap_closure.size()
+ this->_heap_lamret.size();
// Not going to factor in the sizes of the recycle-bins
Expand All @@ -113,6 +121,8 @@ void GarbageCollector::debug() {
<<"\n\tRecyclable: " <<this->_recycle_obj.size()
<<"\nNativeFunction: \n\tSize: " <<this->_heap_nfn.size()
<<"\n\tRecyclable: " <<this->_recycle_nfn.size()
<<"\nNativeFunction: \n\tSize: " <<this->_heap_nfc.size()
<<"\n\tRecyclable: " <<this->_recycle_nfc.size()
<<"\nClosure: \n\tSize: " <<this->_heap_closure.size()
<<"\n\tRecyclable: " <<this->_recycle_closure.size()
<<"\nValueTypes::list_t: \n\tSize: " <<this->_heap_list.size()
Expand Down
10 changes: 8 additions & 2 deletions vm/primitive_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
#include "primitive_methods.hpp"

/* TODO
* Really there needs to be a bit more planning here
* Maybe there should be a bit more planning here....
* I'm trying to make an OOP-style solution in a lang that doesn't
* have a clear, organized approach to OOP...
* have a clear, organized approach to OOP.
*
* 1. Ideally methods would be associated with the constructor and not the object so that they aren't copied so much. (Like JavaScript prototypes)
* 2. Also it would be smart to have the symbols converted so that we don't have to hash so many strings. (lang design not conducive to this)
*
* 1 is not how the solution below is implemented
* 2 would be very difficult without changing language. (ie - make json.decode access vm internals or operator . != [''])
*/

// Remove leading and trailing whitespace
Expand Down

0 comments on commit f9cef94

Please sign in to comment.