Why should Py_INCREF(Py_None) be required before returning Py_None in C?

Missing a Py_INCREF will result in an incorrect counting of references for Py_None, which may lead the interpreter to deallocate Py_None. Since Py_None is allocated statically in the Objects/object.c file: PyObject _Py_NoneStruct = { _PyObject_EXTRA_INIT 1, &PyNone_Type }; And in Include/object.h there is the define: #define Py_None (&_Py_NoneStruct) So what will happen, is that the … Read more

When to use Rc vs Box?

Rc provides shared ownership so by default its contents can’t be mutated, while Box provides exclusive ownership and thus mutation is allowed: use std::rc::Rc; fn main() { let mut a = Box::new(1); let mut b = Rc::new(1); *a = 2; // works *b = 2; // doesn’t } In addition Rc cannot be sent between … Read more

What are the advantages and disadvantages of using ARC? [closed]

What are the advantages and disadvantages of using the new automatic reference counting (ARC) memory management style in an iOS project? An ARC program’s execution is nearly identical to well written MRC. That is, the behavioral differences are often undetectable because both the order of operations and performance are very close. If you already know … Read more

Why don’t purely functional languages use reference counting?

Relative to other managed languages like Java and C#, purely functional languages allocate like crazy. They also allocate objects of different sizes. The fastest known allocation strategy is to allocate from contiguous free space (sometimes called a “nursery”) and to reserve a hardware register to point to the next available free space. Allocation from the … Read more

Should I refer to self.property in the init method with ARC?

Use direct access in partially constructed states, regardless of ARC: – (id)initWithReminder:(Reminder*)reminder_ { self = [super init]; if (self) { reminder = reminder_; // OR reminder = [reminder_ retain]; } return self; } This is because self.whatever will trigger other side effects, such as Key-Value Observing (KVO) notifications, or maybe your class implements (explicitly) or … Read more

Why no Reference Counting + Garbage Collection in C#?

Brad Abrams posted an e-mail from Brian Harry written during development of the .Net framework. It details many of the reasons reference counting was not used, even when one of the early priorities was to keep semantic equivalence with VB6, which uses reference counting. It looks into possibilities such as having some types ref counted … Read more

How to force deletion of a python object?

The way to close resources are context managers, aka the with statement: class Foo(object): def __init__(self): self.bar = None def __enter__(self): if self.bar != ‘open’: print ‘opening the bar’ self.bar=”open” return self # this is bound to the `as` part def close(self): if self.bar != ‘closed’: print ‘closing the bar’ self.bar=”close” def __exit__(self, *err): self.close() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)