reference count

Discussion in 'Python' started by J, Sep 29, 2005.

  1. J

    J Guest

    Hi,


    I have a problem with the reference count after an error occurs
    in a script which I execute as follows..

    PyObject* lDict = PyDict_New();
    PyDict_SetItemString(lDict, "item", (PyObject*)iItem->mPyObject);
    PyObject* lResult = PyEval_EvalCode(mCode, ScnGlobal::sDictionary,
    lDict);
    if (! lResult)
    {
    PyErr_Print();
    }
    else
    {
    Py_DECREF(lResult);
    }
    Py_DECREF(lDict);


    The script within the mCode object only contains the following line,
    which generates an error.

    print aasas


    The problem is that after PyEval_EvalCode returns the reference count
    for lDict is one larger than before. Py_DECREF(lDict) does
    therefore not delete the Dictionary, which causes me problems. Is
    Python keeping an exception around. I assume that I have to do some
    more cleanup ??


    Cheers
    Jochen
    J, Sep 29, 2005
    #1
    1. Advertising

  2. J

    J Guest

    I tend to answer my own questions a lot. But he, lets grow the
    knowledge base :)... PyErr_Clear() after PyErr_Print did the trick....

    J
    J, Sep 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christophe Vanfleteren

    Re: can I get the reference count

    Christophe Vanfleteren, Aug 9, 2003, in forum: Java
    Replies:
    9
    Views:
    3,414
    Tor Iver Wilhelmsen
    Aug 11, 2003
  2. Peter Jones

    setting a reference count to zero

    Peter Jones, Jan 8, 2006, in forum: Java
    Replies:
    10
    Views:
    631
    Dimitri Maziuk
    Jan 10, 2006
  3. Pablo Yabo

    Reference count

    Pablo Yabo, Aug 11, 2003, in forum: Python
    Replies:
    0
    Views:
    332
    Pablo Yabo
    Aug 11, 2003
  4. Fredrik Lundh

    Re: Reference count question

    Fredrik Lundh, Feb 2, 2005, in forum: Python
    Replies:
    2
    Views:
    309
    Fredrik Lundh
    Feb 3, 2005
  5. efelnavarro09
    Replies:
    2
    Views:
    916
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page