总结The reference count behavior of functions in the Python/C API is best explained in terms of ownership of references. Ownership pertains to references,never to objects (objects are not owned: they are always shared). “Owning a reference” means being responsible for calling Py_DECREF on it when the reference is no longer needed. Ownership can also be transferred,meaning that the code that receives ownership of the reference then becomes responsible for eventually decref’ing it by calling Py_DECREF() or Py_XDECREF() when it’s no longer needed—or passing on this responsibility (usually to its caller). When a function passes ownership of a reference on to its caller,the caller is saID to receive a new reference. When no ownership is transferred,the caller is saID to borrow the reference. nothing needs to be done for a borrowed reference.
Conversely,when a calling function passes in a reference to an object,there are two possibilitIEs: the function steals a reference to the object,or it does not. Stealing a reference means that when you pass a reference to a function,that function assumes that it Now owns that reference,and you are not responsible for it any longer.
以上是内存溢出为你收集整理的python – 什么是参考窃取和借用?全部内容,希望文章能够帮你解决python – 什么是参考窃取和借用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)