eivindbakkestuen 46 Posted September 23 I'm using the WrapDelphi unit in a project, so that the TPyDelphiWrapper.CreateComponent function can be available from a Python script. Now, a clever user has come up with a "smart" way of finding available classes; namely, iterate over every possible string of characters and feed the strings into CreateComponent() in the Python script, and catch exceptions raised when the classname doesn't exist. Yes, due to the exponential nature of the search as the strings get longer, its not really a good way of finding long classnames. However, the problem I'm being presented with is that memory runs out long before time does. I have narrowed the problem down to the following (commented out by me for test) PyErr_SetObject call in TPyDelphiWrapper.CreateComponent(). if (Klass = nil) or not Klass.InheritsFrom(TComponent) then begin // PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString( // Format(rs_ErrInvalidArgs, // ['CreateComponent', rs_InvalidClass]))); Exit; end; The inner function in the Python script is the following. My question is, is there something different that needs to be called from the Python script, in order to release memory used by the exception? def typename(k, prefix="T", ab=alphabet): try: w = prefix + int2word(k, ab=ab) t = CreateComponent(w, None) out = ["T" + type(t).__name__] t.Free() del t except: out = [] return out Share this post Link to post
pyscripter 650 Posted September 23 Could you please post a minimal project (zipped) demonstrating the memory leak? Share this post Link to post
pyscripter 650 Posted September 23 (edited) This was a reference counting bug. This is now fixed in version control. See Memory leak when PyErr_SetObject is used · Issue #485 · pyscripter/python4delphi (github.com). Could you please try with the latest version and report whether the issue is solved. Edited September 23 by pyscripter 1 Share this post Link to post
eivindbakkestuen 46 Posted September 30 Thanks a million! With the latest version, I no longer see the memory leak. Share this post Link to post