Jump to content
eivindbakkestuen

How to release memory used by exceptions?

Recommended Posts

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

Could you please post a minimal project (zipped) demonstrating the memory leak?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×