reference-counting

Why doesn't std::shared_ptr use reference linking?

丶灬走出姿态 提交于 2020-01-13 16:28:13
问题 std::shared_ptr needs to allocate a control block on the heap which holds the reference count. There was another approach I learnt from http://ootips.org/yonat/4dev/smart-pointers.html which keeps all the references in a doubly linked list. It doesn't need additional allocations nor a counter but the reference object itself is larger. Is there a benchmark or any clear reason showing one implementation is better than the others? 回答1: The standard does in theory allow a linked list to be used,

How to implement reference counted objects in Delphi

亡梦爱人 提交于 2020-01-11 07:33:09
问题 I have a graph like structure. I don't know exactly when to destroy the objects in traditional Delphi manner, instead I would like to implement something like reference counted objects. I know that I can use something like object.GetReference and object.Release instead of Free, and use a private variable for reference counting, but is there any better way? Thanks 回答1: If you have problems determining the correct way (place, order and so on) of destroying standard objects in a Delphi program,

How to implement reference counted objects in Delphi

一曲冷凌霜 提交于 2020-01-11 07:33:05
问题 I have a graph like structure. I don't know exactly when to destroy the objects in traditional Delphi manner, instead I would like to implement something like reference counted objects. I know that I can use something like object.GetReference and object.Release instead of Free, and use a private variable for reference counting, but is there any better way? Thanks 回答1: If you have problems determining the correct way (place, order and so on) of destroying standard objects in a Delphi program,

Incorrect codelens references in VS 2013 ultimate

冷暖自知 提交于 2020-01-02 09:21:10
问题 I am not sure if this is by design or need to enable/disable features in VS 2013 ultimate but the reference counts generated by the codelens is completely out of whack. Instead of showing the count of classes/methods directly referencing a particular class/method, it shows the count of everything that has the same name as the class/method in the entire solution. For example, say I have four classes in my solution (doesn't matter four projects with one class in each). using System; using

Why are Python Ref Counts to small integers surprisingly high?

我与影子孤独终老i 提交于 2020-01-01 04:41:04
问题 In this answer I found a way to get a reference count of objects in Python. They mentioned using sys.getrefcount() . I tried it, but I'm getting an unexpected result. When there is 1 reference, it seems as though the count is 20. Why is that? I looked at the documentation but it doesn't seem to explain the reason. 回答1: This object happens to have 20 references to it at the time of the first sys.getrefcount call. It's not just the references you created; there are all sorts of other references

Code Example: Why can I still access this NSString object after I've released it?

老子叫甜甜 提交于 2019-12-31 01:28:08
问题 I was just writing some exploratory code to solidify my understanding of Objective-C and I came across this example that I don't quite get. I define this method and run the code: - (NSString *)stringMethod { NSString *stringPointer = [[NSString alloc] initWithFormat:@"string inside stringPointer"]; [stringPointer release]; [stringPointer release]; NSLog(@"retain count of stringPointer is %i", [stringPointer retainCount]); return stringPointer; } After running the code and calling this method,

Dealing with circular strong references in Delphi

我的梦境 提交于 2019-12-30 18:33:52
问题 I got two classes (in my example TObject1 and TObject2) which know each other via interfaces (IObject1, IObject2). As you probably know in Delphi this will lead to a memory leak as both reference counter will always stay above zero. The usual solution is declaring one reference as weak. This works in most cases because you usually know which one will be destroyed first or don't necessarily need the object behind the weak reference once it is destroyed. This said I tried to solve the problem

Reference count is still 1 after [obj release], when it should be deallocated

狂风中的少年 提交于 2019-12-30 11:11:23
问题 When I create an object and check its retain count, I get 1 as expected. When I release the object and then check the retain count again, it is still 1. Shouldn't the object be deallocated, and the retain count 0? NSMutableString *str=[[NSMutableString alloc] initWithString:@"hello"]; NSLog(@"reference count is %i",[str retainCount]); [str release]; NSLog(@"reference count is %i",[str retainCount]); I do see 0 for the retain count if I set str to nil first. Why is that? 回答1: Don't use

Reference cycles with value types?

给你一囗甜甜゛ 提交于 2019-12-28 04:08:10
问题 Reference cycles in Swift occur when properties of reference types have strong ownership of each other (or with closures). Is there, however, a possibility of having reference cycles with value types only ? I tried this in playground without succes ( Error: Recursive value type 'A' is not allowed ). struct A { var otherA: A? = nil init() { otherA = A() } } 回答1: A reference cycle (or retain cycle ) is so named because it indicates a cycle in the object graph: Each arrow indicates one object

How does Rust handle the “island of isolation” (cycles of references) scenario for reference-counted types?

断了今生、忘了曾经 提交于 2019-12-23 07:28:45
问题 How does Rust handle the "island of isolation" scenario for Rc s and Arc s? An "island of isolation" is a situation where object A contains a pointer to object B and object B contains a pointer to object A , but there are no pointers to either objects anywhere else. Is Rust smart enough to detect this or does it lead to memory leaks? 回答1: Rust does not have a garbage collector, and it won't detect reference cycles. If your program creates inaccessible reference cycles, they are leaked, and it