Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork320
How do I free objects after the script execution?#455
-
I have set of scripts that produce and use objects like this:
If I comment the last line, rb seems not to be released automatically. |
BetaWas this translation helpful?Give feedback.
All reactions
The following code solves my issue. I hope it will be useful for someone else.
fPyDelphiObjects - is a TDictionary<string, PPyObject>, where I keep all the P4D objects, that were created during script execution.
So this code is kinda my own garbage collector.
I would also appreciate to receive any comments on this method, if it has mistakes or vulnerables.
procedure TDeepyPythonModule.ReleasePyObjects;begin var aScript := TStringList.Create; try var aGlobals := GetPythonEngine.EvalString('globals()'); var aKeys := GetPythonEngine.PyDict_Keys(aGlobals); try for var I := 0 to GetPythonEngine.PySequence_Length(aKeys) - 1 do begin var aKey := GetPythonEngi…
Replies: 7 comments 4 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Run:
I don't know how to do it automatically |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
In my Delphi project I have list of produced PyObjects, but of course I don't know names of the variables that store them. |
BetaWas this translation helpful?Give feedback.
All reactions
-
AFAIR |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
The following code solves my issue. I hope it will be useful for someone else. I would also appreciate to receive any comments on this method, if it has mistakes or vulnerables.
|
BetaWas this translation helpful?Give feedback.
All reactions
-
here is how to get globals w/o calculating 'globals()'
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Why is it better? Will it save a lot of resources? |
BetaWas this translation helpful?Give feedback.
All reactions
-
also: you call GetPythonEngine 10 times. cache it to var. |
BetaWas this translation helpful?Give feedback.
All reactions
-
also: |
BetaWas this translation helpful?Give feedback.
All reactions
-
This was my first shot - just to iterate the fPyDelphiObjects dict and to decrease the reference counter, but it lead to the AV in the following scripts when using the same variable. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
You can change your code to the following so that you do not pollute the main module dictionary. defdowork():frompc1importPcaspcrb=pc.ReceiptBuilder()# work with receipt builderdowork() |
BetaWas this translation helpful?Give feedback.
All reactions
-
I'm just a beginner in Python. |
BetaWas this translation helpful?Give feedback.