motion-memorymanagement 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -10,24 +10,52 @@ This gem provides weak references and autorelease pools for your ruby code!
10
10
  require 'motion-memorymanagement'
11
11
  ```
12
12
 
13
- ### Available API demos
13
+ ## Usage
14
+
15
+ Motion::MemoryManagement is effectively a stripped version of [https://github.com/mikeash/MAZeroingWeakRef](MAZeroingWeakRef), all the appropriate classes are available in RubyMotion.
16
+
17
+ It also provides two helper methods to simplify usage for weak references and weak proxy objects.
18
+
19
+ Finally, it provides a way to wrap some ruby code in ```@autorelease { ... }``` block (I expect you know what you're doing!).
20
+
21
+ ### MAZeroingWeakRef
22
+
23
+ ```MAZeroingWeakRef``` is the primary interface to use.
14
24
 
15
25
  ```ruby
16
- class Test
17
- def method
18
- "hello"
19
- end
20
- end
26
+ # make reference
27
+ obj = self.some_data
28
+ weak_ref = obj.to_weakref # same as MAZeroingWeakRef.refWithTarget(obj)
29
+
30
+ # use reference
31
+ weak_ref.target # will become nil automagically as soon as obj is "garbage-collected"
32
+ ```
33
+
34
+ ### MAZeroingWeakProxy
21
35
 
22
- t = Test.new
23
- wt = t.weak!
36
+ ```MAZeroingWeakProxy``` is effectively a proxy class around your object. This may or may
37
+ not be what you want, because the message dispatch goes right through Objective-C runtime.
38
+ If unsure, use ```MAZeroingWeakRef```.
24
39
 
25
- wt.method # => "hello"
40
+ ```ruby
41
+ # make reference
42
+ obj = self.some_data
43
+ weak_ref = obj.to_weakproxy # same as MAZeroingWeakProxy.proxyWithTarget(obj)
26
44
 
27
- t = nil
28
- wt.method # => nil
45
+ # use reference
46
+ weak_ref.method_of_obj # if 'obj' is gone, it will be same as calling method on nil,
47
+ # that is, it will do nothing and return nil
29
48
  ```
30
49
 
50
+ ### MAWeakArray and MAWeakDictionary
51
+
52
+ That are mutalbe array and dictionary with added feature that the stored objects are
53
+ weak-referenced (i.e. objects on array or keypairs in dictionary may be zeroed out).
54
+
31
55
  ### Notes
32
56
 
33
- Lots of thanks to Mike Ash for his MAZeroingWeakRef!
57
+ By default, all objects created in ruby scope are put into nearest local autorelease pool.
58
+ Effectively meaning that no object would go away until current method ends returning control
59
+ to the event loop.
60
+
61
+ Lots of thanks to Mike Ash for his MAZeroingWeakRef!
@@ -2,7 +2,7 @@ describe "Memory management" do
2
2
  it "keeps zero weak refs zeroed if referenced objects are gone" do
3
3
  zwr = MMAutoreleased -> {
4
4
  obj = "hello"
5
- zwr = MAZeroingWeakRef.refWithTarget(obj).retain # that what happens if you neer to be smarter than runtime!
5
+ zwr = obj.to_weakref.retain # that what happens if you neer to be smarter than runtime!
6
6
  obj = nil
7
7
  zwr
8
8
  }
@@ -12,7 +12,7 @@ describe "Memory management" do
12
12
 
13
13
  it "keeps zero weak refs alive if referenced objects are alive" do
14
14
  obj = "hello"
15
- zwr = obj.weak!
15
+ zwr = obj.to_weakproxy
16
16
  zwr.length.should == 5
17
17
  end
18
18
 
@@ -24,9 +24,9 @@ describe "Memory management" do
24
24
  end
25
25
 
26
26
  t = MMAutoreleased -> {
27
- t = Test.alloc.init.retain
27
+ Test.alloc.init.retain
28
28
  }
29
- wt = t.weak!
29
+ wt = t.to_weakproxy
30
30
 
31
31
  wt.method.should == "hello"
32
32
 
@@ -1,5 +1,9 @@
1
1
  class Object
2
- def weak!
2
+ def to_weakref
3
+ MAZeroingWeakRef.refWithTarget(self)
4
+ end
5
+
6
+ def to_weakproxy
3
7
  MAZeroingWeakProxy.proxyWithTarget(self)
4
8
  end
5
9
  end
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module MemoryManagement
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,33 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: motion-memorymanagement
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Vladimir Pouzanov
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2013-01-23 00:00:00 +00:00
18
- default_executable:
12
+ date: 2013-01-23 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Memory management (weak references and autorelease pools) for RubyMotion
22
- email:
15
+ email:
23
16
  - farcaller@gmail.com
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - .gitignore
32
22
  - Gemfile
33
23
  - LICENSE
@@ -56,35 +46,29 @@ files:
56
46
  - lib/motion-memorymanagement/runtime_helpers.rb
57
47
  - lib/motion-memorymanagement/version.rb
58
48
  - motion-memorymanagement.gemspec
59
- has_rdoc: true
60
- homepage: ""
49
+ homepage: ''
61
50
  licenses: []
62
-
63
51
  post_install_message:
64
52
  rdoc_options: []
65
-
66
- require_paths:
53
+ require_paths:
67
54
  - lib
68
- required_ruby_version: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 0
74
- version: "0"
75
- required_rubygems_version: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
- version: "0"
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
82
67
  requirements: []
83
-
84
68
  rubyforge_project:
85
- rubygems_version: 1.3.6
69
+ rubygems_version: 1.8.21
86
70
  signing_key:
87
71
  specification_version: 3
88
72
  summary: Memory management for RubyMotion
89
73
  test_files: []
90
-
74
+ has_rdoc: