Questions tagged [weak]
128 questions
7
votes
2 answers
Python - how to check if weak reference is still available
I am passing some weakrefs from Python into C++ class, but C++ destructors are actively trying to access the ref when the real object is already dead, obviously it crashes...
Is there any Python C/API approach to find out if Python reference is…

Alex
- 105
- 3
7
votes
3 answers
JIT Optimization and Weak References
I have the following piece of code:
private final List> slaves;
public void updateOrdering() {
// removes void weak references
// and ensures that weak references are not voided
// during subsequent sort
List…

user2609605
- 419
- 2
- 14
6
votes
2 answers
Unowned self in a closure in a closure
If I have a closure in another closure is it enough to use unowned/weak once in the outer closure to avoid retain cycles?
Example:
foo.aClosure({[unowned self] (allowed: Bool) in
if allowed {
self.doStuff()
…

lukas_o
- 3,776
- 4
- 34
- 50
6
votes
2 answers
GCC behavior for unresolved weak functions
Consider the simple program below:
__attribute__((weak)) void weakf(void);
int main(int argc, char *argv[])
{
weakf();
}
When compiling this with gcc and running it on a Linux PC, it segfaults. When running it on ARM CM0…

calandoa
- 5,668
- 2
- 28
- 25
6
votes
2 answers
SoftReferences vs Weakreferences / OutOfMemoryError
I got a problem dealing with soft and weak references. Code has a flag that switches
all logic between soft and weak references. And while with weak references all seems
to be working ok, with soft references I am consistently getting…

jarek
- 61
- 2
5
votes
2 answers
iOS ARC - weak and strong properties
I'm trying to understand the way ARC works, and as far as I know, I should be doing something wrong here. This is the code I'm using:
Interface:
@interface ViewController : UIViewController{
}
@property (strong, nonatomic) NSString * myString ;…

RGML
- 3,429
- 2
- 22
- 18
5
votes
2 answers
How to instantiate a weak delegate without triggering "Instance will be immediately deallocated because property 'tableViewDelegate' is 'weak'"
I am trying to separate out my tableView's datasource into a separate delegate object. Since that delegate needs to access the tableview at some point I need a reference to the delegating object in the delegate; and since both are classes I need to…

thecloud_of_unknowing
- 1,103
- 14
- 23
5
votes
1 answer
Should self be weak in UIView.animate when there is a delay and in collection view perform batch updates?
In general I'm aware that we do not need to make self weak when using UIView.animate() because the block isn't held strongly but is there an argument for using weak in the following bit of code due to the delay? Why would someone say there could…

jeh
- 2,373
- 4
- 23
- 38
4
votes
2 answers
Cross-Store weak relationship with Fetched Properties?
I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part…

Clement M
- 709
- 6
- 14
4
votes
3 answers
Is there a way to override a module's main function in the D programming language?
If you really need to, you can specify __attribute__((weak)) in C (see scriptedmain). This allows a program to double as API and executable, allowing code that imports the API to overwrite the main function.
Does D have a way to do this? Python has…

mcandre
- 22,868
- 20
- 88
- 147
4
votes
3 answers
When does a Class object get garbage collected?
I was wondering if somebody could tell me when a Java Class object gets garbage collected. My use case is a cache (Map, Class>[]>) which holds the class-hierarchy of objects.
For instance:
The (short) hierarchy of String.class would be…

Kr0e
- 2,149
- 2
- 24
- 40
4
votes
2 answers
Confusions about weak delegate in swift
Let us suppose we have a protocol
protocol MyProtocol {
fun someFunc()
}
class AClass {
var delegate: MyProtocol?
}
AClass doesn't care if the delegate is a class or struct. What I want is sometimes the delegate can be a class and…

echo
- 1,244
- 1
- 16
- 40
4
votes
1 answer
Swift XCTest: Verify proper deallocation of weak variables
Recently I was attempting to verify that an object I wrote properly deallocates using a unit test. I found however that no matter what I tried the object would not deallocate before the test completed. So I reduced the test to a trivial example…

Patrick Goley
- 5,397
- 22
- 42
4
votes
2 answers
Swift generic reference type
I'm having issues trying to constrain generic type requirements to just reference types. Here's some example code:
class WeakHolder {
weak var element: Element?
init(element: Element) {
self.element = element
…

Mark
- 7,167
- 4
- 44
- 68
4
votes
2 answers
My template specialization differs debug version from release version, is this gcc bug?
First of all, I've got a header file for a class, an specialization declaration without definition(code samples from internet)
$ cat foo.h
template
class foo{
public:
static void init(){
return;
}
};
template<> void…

Troskyvs
- 7,537
- 7
- 47
- 115