forcing stdcpp gc?
Monkey Forums/Monkey Programming/forcing stdcpp gc?
| ||
Hello This simple program runs into a memory overflow: Strict Class Fake End Function Main:Int() Local f:Fake Repeat f = New Fake() f = Null Forever End Any Idea, how i can manually force the gc on stdcpp? |
| ||
You can use the 'gc_collect' and 'gc_collect_all' commands via external functions.Function GCCollect:Void()="gc_collect" Function GCCollect_All:Void()="gc_collect_all" That should work well enough. I'm no expert on Monkey's garbage collector these days, but you shouldn't have an issue with these. Generally speaking, you shouldn't need 'GCCollect_All', as it's done automatically when calling 'GCCollect', but I figured I'd set it up anyway. |
| ||
You should use incremental garbage collector instead for this kind of apps, instead of manually calling for collection. |
| ||
When i use gc_collect(), i become an MAV Error :/ @ziggy you mean, the garbage collector for stdcpp is not usable? |
| ||
you mean, the garbage collector for stdcpp is not usable Yes it is! By default it'll calculate if collection is needed after every OnWhatever on Mojo. If you want to use it on a standard cpp app that does not use Mojo, or on any application that produces tones of allocations per frame, you should enable the incremental GC on every allocation. From the documentation: #CPP_GC_MODE=1 '0 disable GC, 1=incremental collect after every OnWhatever, 2=Incremental collect every GC allocation Just set it to: #CPP_GC_MODE=2 |
| ||
Thanks for the Information, but the Program crashes at random time :/ |
| ||
What kind of classes do you create (and why)? Maybe there is a better way of handling this?! |
| ||
Im working on a simple tcp http server with monkey, I do all in pure monkey, only 4 functions are extern |