weak-references

Swift Weak Reference Much Slower than Strong Reference

淺唱寂寞╮ 提交于 2020-07-03 03:43:31
问题 I'm building a physics engine in Swift. After making some recent additions to the engine and running the benchmarking tests I noticed the performance was drastically slower. For example, in the screenshots below you can see how the FPS dropped from 60 to 3 FPS (FPS is in the bottom-right corner). Eventually, I traced the problem down to just a single line of code: final class Shape { ... weak var body: Body! // This guy ... } At some point in my additions I added a weak reference from the

Kivy : Error weakly-referenced object (in a clock function) no longer exists

家住魔仙堡 提交于 2020-06-17 03:53:25
问题 So here is my error code I think there's something hard in this error, i looked on forums but couldn't find out. And ... i have the error on my phone (with kivy launcher python 3 and when i build with buildozer) but not on my computer (ubuntu 18.0.4 and windows 10) The error, from what i understand, comes from the garbage collector that delete a reference and the code try to access the reference after the garbage collector. but i am not sure if I rly understand the garbage collector thing

Why weakref doesn't support built-in types in Python?

浪尽此生 提交于 2020-05-23 05:53:08
问题 In Python weakref document( http://docs.python.org/library/weakref.html ), it says that Several built-in types such as list and dict do not directly support weak references but can add support through subclassing I think creating weakref for big dict could be useful in some real cases. I'm wondering what's the reason behind that implementation ? 回答1: Most of the built-in types are not directly weak referenceable (e.g. str, int, float, list, dict, None), and there are a few that cannot even be

JVM - Are WeakReferences collected in minor GC?

我只是一个虾纸丫 提交于 2020-05-08 03:39:40
问题 I was wondering about that since that would make them less useful. If so, is there a way to make memory weakly referenced only "garbage" on major GC? 回答1: The javadoc does not specifically state what the "timescales" are for clearing / breaking WeakReference s. That would make the answer to your question (at least in theory) "it is implementation dependent". Indeed, the JLS spec and javadocs don't even mention major versus minor collections. The whole topic comes is in the "implementation

Weak method argument semantics

╄→尐↘猪︶ㄣ 提交于 2020-04-10 03:14:11
问题 Is there any way to specify that a particular method argument has weak semantics? To elaborate, this is an Objective-C sample code that works as expected: - (void)runTest { __block NSObject *object = [NSObject new]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self myMethod:object]; }); // to make sure it happens after `myMethod:` call dispatch_async(dispatch_get_main_queue(), ^{ object = nil; }); } - (void)myMethod:(__weak id)arg0 { NSLog(@"%@", arg0); //

Scoped Variables and WeakReferences interact strangely - some objects don't get garbage collected

随声附和 提交于 2020-03-18 07:01:38
问题 I am seeing some strange behavior in a Java program, and I'm wondering if the behavior is expected, and if it's documented anywhere. I am placing some WeakReference objects into a collection. (Yes, I know I should use WeakHashMap -- it has the same odd behavior, and that's not what this question is about.) In some circumstances, the object referenced by the last WeakReference placed into the collection does not get garbage collected when I expect it to. Below, there is a collection of unit

Thread Safety of WeakReference

主宰稳场 提交于 2020-03-13 05:46:32
问题 When using a WeakReference, how can we be sure than the target is not collected between the .IsAlive and .Target calls? For example: if (myWeakReference.IsAlive) { // How can we be sure the object is still alive while here? ((MyType)myWeakReference.Target).Foo(); } 回答1: Just get the Target and check whether it's not null: object target = myWeakReference.Target; if (target != null) { ((MyType)target).Foo(); } The docs for IsAlive specifically say: Because an object could potentially be

Lots of overhead for weak property?

烂漫一生 提交于 2020-01-24 04:45:07
问题 My iOS app stalls on setDelegate for about 15 seconds after about 100,000 setDelegate calls. Changing the delegate property from weak to assign fixes the problem. Any idea why the weak property has so much overhead and stalls the app? I suspect the weak references are maintained in an array so the runtime can loop thru them and set the pointers to nil when the delegate object gets deallocated. Does the array have a max size? The stall gets much longer as n nears 100,000. Sample code is below:

WeakReference Behavior When Object Is Finalized But Not Yet Garbage Collected

穿精又带淫゛_ 提交于 2020-01-22 20:50:10
问题 Here's an academic question about object finalization and collection in C#/.NET. Background reading is section 3.9 of the C# language spec, Automatic Memory Management. When there are no explicit references to an object, it may become garbage collected. It becomes "eligible for destruction". At some point in the future (e.g. if you force garbage collection), the object's destructor will be run. In the destructor, if you save a reference to the object, the object will be finalized, but will

Using weak self in dispatch_async function

只愿长相守 提交于 2020-01-18 11:08:08
问题 I read a lot of posts about using __weak self inside dispatch_async , and now I am a litle bit confused. if I have : self.myQueue = dispatch_queue_create("com.biview.core_data", NULL); dispatch_async(self.myQueue, ^(void){ if (!self.var1) { self.var1 = ...; } dispatch_async(dispatch_get_main_queue(), ^(void) { if ([self.var2 superview]) { [self.var2 removeFromSuperview]; } [self.Label setText:text]; }); }); do I need to use __weak self . Because I read that in some cases dispatch_async not