Questions tagged [refcounting]
56 questions
5
votes
5 answers
Why shared_ptr has an explicit constructor
I was wondering why shared_ptr doesn't have an implicit constructor. The fact it doesn't is alluded to here: Getting a boost::shared_ptr for this
(I figured out the reason but thought it would be a fun question to post anyway.)
#include…

cdleary
- 69,512
- 53
- 163
- 191
5
votes
2 answers
Missing shared_ref
While working with std::shared_ptr a lot I kind of miss a shared_ref implementation. That is a specialization of shared_ptr, which guarantees, that it never wraps a nullptr (given right usage, of course).
I kind of wonder why it is not in the C++11…

abergmeier
- 13,224
- 13
- 64
- 120
4
votes
1 answer
recursive reference in Perl
$a=\$a;
The book I'm reading says in this case $a will NEVER be free,my question is why perl interpreter doesn't fix it at compile time?When it finds it's pointing at itself,don't increase refcount.
Why perl doesn't do it?

new_perl
- 7,345
- 11
- 42
- 72
4
votes
1 answer
Strange behaviour of ref counter with ints being 0
I was fiddling with the ctypes module of python to better understand how the garbage collector works. Playing in the interpreter, I came through this strange situation :
>>>import ctypes
>>>def get_ref(obj):
... """ This returns the refcount of…

Jokyjo
- 144
- 1
- 8
3
votes
2 answers
slow memory release (refcounted structure) - Is my workaround a good way?
in my program i can load a Catalog: ICatalog
a Catalog here contains a lot of refcounted structures (Icollections of IItems, IElements, IRules, etc.)
when I want to change to another catalog,
I load a new Catalog
but the automatic release of the…

DamienD
- 369
- 4
- 12
3
votes
1 answer
How to correctly use grpc asynchronously (ClientAsyncReaderWriter)
I can't find a grpc example showing how to use the ClientAsyncReaderWriter (is there one?). I tried something on my own, but am having trouble with the reference counts. My question comes from tracing through the code.
struct grpc_call has a…

ezLeo
- 31
- 1
- 3
3
votes
2 answers
python refcounts
So Python Essential Reference, 4 ed. says:
a = {}
b = {}
a['b'] = b
b['a'] = a
del a
del b
creates a memory leak, and the interpreter need a cycle detection algorithm to delete a and b.
However, when I tried to work out how the refcount are, it…

Schitti
- 25,489
- 8
- 24
- 21
3
votes
1 answer
ARC migrator returns error in other target
I'm trying to convert an older project to ARC. My project relies on Cocos2D, which is a 3rd party non-ARC library. All the Cocos2D source files are part of a separate target and are compiled to a static library.
However, the ARC migrator returns ARC…

Jawap
- 2,463
- 3
- 28
- 46
2
votes
1 answer
How do I debug refcounts in a Python C-extension the easiest way?
So I have put together a few Python C-extensions and although their respective behaviors are verified, I'd like to verify this by some refcount debugging.
How can I verify that I have inserted the INC/DEC refcounts properly? I want to do this…

c00kiemonster
- 22,241
- 34
- 95
- 133
2
votes
1 answer
Weak pointer library implementation C++
#include
using namespace std;
class Printer
{
weak_ptr m_Value{};
public:
void SetValue(weak_ptr p)
{
m_Value = p;
}
void Print() const
{
cout << "ref count = " << m_Value.use_count() <<…

amutamil
- 35
- 4
2
votes
1 answer
Strange xdebug_debug_zval behavior on function parameters -- incorrect (?) refcount displayed
Here's the code:
The output is:
b: (refcount=3, is_ref=0)=10
b: (refcount=3,…

mlvljr
- 4,066
- 8
- 44
- 61
2
votes
1 answer
(Ab)using shared_ptr as a reference counter
Recently i thought of a cunning plan(tm :P))
I have to update settings structure in my program(lets say every 15 seconds). Settings structure is used by multiple functions and every of those functions is called by multiple threads.
So I need a…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
2
votes
2 answers
How to avoid freeing objects that are stored in containers with the same reference count
I have been working on some features of a custom programming language written in c. Currently i'm working on a system that does reference counting for objects in the language, which in c are represented as structs with among other things, a…

jonathan
- 590
- 3
- 14
2
votes
3 answers
Why is my C module leaking memory?
I'm reading lists from a large file, which I eventually want to store as array.arrays. Because
map(int, line.split())
is very slow, I wrote a small C module which does strtok and a faster version of atoi:
inline long
minhashTables_myatoi(const…

chuck
- 493
- 3
- 9
2
votes
3 answers
Why did instruments report a leak while its ref count did become zero
green hand i am. I'm using instruments, and it did a great help to me so far, but I'm confused now 'cause it report a memory leak to me while its leaked block history shows me that the ref count of that memory had finally become 0. What does it…

bromj
- 61
- 4