weak-references

Android: the GC doesn't respect SoftReferences?

隐身守侯 提交于 2019-12-03 13:23:44
问题 It seams that Dalvik's garbage collector doesn't respect SoftReferences and removes them as soon as possible, just like WeakReferences. I'm not 100% sure yet, but despite the fact that there is still ~3MB of free memory my SoftReferences get cleared after I see "GC freed bla-bla-bla bytes" in LogCat. Also, I saw a comment by Mark Murphy here: Except that it doesn't work on Android, at least in the 1.5 timeframe. I have no idea if the GC SoftReference bugs have been fixed. SoftReferences get

One Liner: WeakReference-to-a-Lambda Event Handler

别等时光非礼了梦想. 提交于 2019-12-03 13:05:52
Can you see downsides to this one-liner other than the fact that multiple uses of it would violate the DRY principle? It seems straightforward but the fact that I haven't seen others propose it makes me wonder if there's a downside to it. This bit of code creates a WeakReference to a method and then registers an event handler that invokes the reference's target. SomeEvent += (sender, e) => ((Action)(new WeakReference((Action)ProcessEvent)).Target)(); Thanks, Ben I don't think that pattern does what you expect. Are you trying to prevent the event from holding a reference to the current object

Python: which types support weak references?

丶灬走出姿态 提交于 2019-12-03 12:12:49
Code: from weakref import WeakSet se = WeakSet() se.add(1) Output: TypeError: cannot create weak reference to 'int' object Doc : Several built-in types such as list and dict do not directly support weak references but can add support through subclassing: ... Other built-in types such as tuple and int do not support weak references even when subclassed (This is an implementation detail and may be different across various Python implementations.). This isn't expressive enough to explain: Why some built-in types don't support weak references? What are exactly those types that support weak

Two weak variables referencing each other in Swift?

两盒软妹~` 提交于 2019-12-03 11:39:24
I'm making another attempt today to try to understand retain cycles and weak references in Swift. Reading through the documentation , I saw the following code example where one of the referencing variables is marked as weak to prevent a retain cycle: class Person { let name: String init(name: String) { self.name = name } var apartment: Apartment? deinit { print("\(name) is being deinitialized") } } class Apartment { let unit: String init(unit: String) { self.unit = unit } weak var tenant: Person? // <---- This var is marked as 'weak' deinit { print("Apartment \(unit) is being deinitialized") }

JVM G1GC's mixed gc not collecting much old regions

自作多情 提交于 2019-12-03 10:35:05
问题 My server is using 1.8.0_92 on CentOS 6.7, GC param is '-Xms16g -Xmx16g -XX:+UseG1GC'. So the default InitiatingHeapOccupancyPercent is 45, G1HeapWastePercent is 5 and G1MixedGCLiveThresholdPercent is 85. My server's mixed GC starts from 7.2GB, but it clean less and less, finally old gen keeps larger than 7.2GB, so it's always try to do concurrent mark. Finally all heap are exhausted and full GC occurred. After full GC, old gen used is under 500MB. I'm curious why my mixed GC can't collect

Can `weakref` callbacks replace `__del__`?

陌路散爱 提交于 2019-12-03 10:13:17
Is there any obstacle that prevents weakref from doing everything that __del__ does but with much stronger guarantees (e.g., finalize guarantees that the call will be made before the interpreter exits, and the order of calls is well-defined, etc.)? It seems that in the distant past it was thought that weakref would eventually lead to the removal of __del__ from the language. What prevented this from happening? There seems to be few use cases for __del__ , and all the ones I'm aware of seem to work at least as well (and usually much better) with weakref callbacks or weakref.finalize . Update:

I have a circular reference. How can I create a weak reference in Objective-C?

蓝咒 提交于 2019-12-03 09:51:20
I'm working on an iPhone application. I have an object of class Row that needs to release numerous objects of the class Block . Every Block currently has a property that retains an instance variable of class Row . @interface Block : UIImageView { Row *yCoord; } @property (nonatomic,retain) Row *yCoord; @end Every Row contains an NSMutableArray of these Blocks. @interface Row : NSObject { NSMutableArray *blocks; } -(void)addBlock:(Block*)aBlock; @end @implementation Row -(void)addBlock:(Block*)aBlock { [blocks addObject:aBlock]; aBlock.yCoord = self; } @end I understand that this is a circular

Creating views programmatically Strong Vs Weak subviews in controller

扶醉桌前 提交于 2019-12-03 09:09:37
I am writing a small test program using Xcode 5.1.1, for iOS 7.1. I am not using Xib or Storyboard. Everything is done programmatically. In the AppDelegate.m, I create an instance of my TestViewController and set it as the rootViewController of the window. Inside TestViewController.m, I override the "loadView" to create and assign the main view of the controller. TestViewController.h -------------------- @interface TestViewController : UIViewController @property (nonatomic, weak) UILabel *cityLabel ; @end TestViewController.m -------------------- @implementation TestViewController - (void

How to keep track of instances of python objects in a reliable way?

ⅰ亾dé卋堺 提交于 2019-12-03 06:57:20
I would like to be able to keep track of instances of geometric Point objects in order to know what names are already "taken" when automatically naming a new one. For instance, if Points named "A", "B" and "C" have been created, then the next automatically named Point is named "D". If Point named "D" gets deleted, or its reference gets lost, then name "D" becomes available again. The main attributes of my Point objects are defined as properties and are the quite standard x , y and name . Solution with a problem and a "heavy" workaround I proceeded as described here , using a weakref.WeakSet()

WeakHashMap and strongly referenced value

怎甘沉沦 提交于 2019-12-03 06:46:52
Javadocs says "When a key has been discarded its entry is effectively removed from the map". But unless there is another thread that occasionally removes such Map.Entry entries, won't the value objects be strongly referenced by the map? But since there is no such thread running, only the get method invocations can remove such entries - one at a time. I almost always use WeakHashMap<K, WeakReference<V>> for that reason. Why would they not have made that the default behavior - values as weak references too? Reference queues are used to automatically remove entries. http://docs.oracle.com/javase