Skip to content

Commit

Permalink
hopefully reduce memory leaks and add a mechanism for relaunching Mem…
Browse files Browse the repository at this point in the history
…oryTamer when it starts using up too much memory
  • Loading branch information
henderea committed Aug 12, 2014
1 parent 9f3b6dc commit 8f266b1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men
* **v0.9.3:** Auto-threshold has changed. My original design for it didn't turn out well, so I changed it to set the thresholds to a certain percent of post-freeing memory on a full freeing. Hopefully this will work better.
* **v0.9.4:** fix a refreshing issue with auto-threshold
* **v0.9.5:** hopefully work around a memory leak by using a bundled copy of growlnotify; also, new icon
* **v0.9.6:** hopefully reduce memory leaks and add a mechanism for relaunching MemoryTamer when it starts using up too much memory

###Versions (code-signed with developer ID):
* **v0.3:** <http://memorytamer.s3.amazonaws.com/MemoryTamer-0.3.zip> (Mavericks-only)
Expand Down Expand Up @@ -66,3 +67,4 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men
* **v0.9.3:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.3.zip>
* **v0.9.4:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.4.zip>
* **v0.9.5:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.5.zip>
* **v0.9.6:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.6.zip>
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Motion::Project::App.setup do |app|
app.icon = 'Icon.icns'
app.info_plist['CFBundleIconFile'] = 'Icon.icns'
app.name = 'MemoryTamer'
app.version = '0.9.5'
app.short_version = '0.9.5'
app.version = '0.9.6'
app.short_version = '0.9.6'
app.identifier = 'us.myepg.MemoryTamer'
app.info_plist['NSUIElement'] = 1
app.info_plist['SUFeedURL'] = 'https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml'
Expand Down
31 changes: 31 additions & 0 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ def to_weak
end
end

class NSApplication
# -(void) relaunchAfterDelay : (float) seconds
# {
# NSTask *task = [[[NSTask alloc] init] autorelease];
# NSMutableArray *args = [NSMutableArray array];
# [args addObject: @ "-c"];
# [args addObject: [NSString stringWithFormat: @ "sleep %f; open \"%@\"", seconds, [[NSBundle mainBundle] bundlePath]]];
# [task setLaunchPath: @ "/bin/sh"];
# [task setArguments: args];
# [task launch];
#
# [self terminate : nil];
# }
def relaunchAfterDelay(seconds)
task = NSTask.alloc.init
args = []
args << '-c'
args << ('sleep %f; open "%s"' % [seconds, NSBundle.mainBundle.bundlePath])
task.launchPath = '/bin/sh'
task.arguments = args
task.launch

self.terminate(nil)
end
end

class AppDelegate
attr_accessor :free_display_title

Expand Down Expand Up @@ -113,9 +139,14 @@ def applicationDidFinishLaunching(notification)
GrowlApplicationBridge.setGrowlDelegate(self)
NSLog "Starting up with memory = #{dfm}; pressure = #{Persist.store.pressure}"
Thread.start {
@start_time = NSDate.date
@last_free = NSDate.date - 30
@last_trim = NSDate.date
loop do
if MemInfo.getMTMemory > (200 * (1024 ** 2)) && (NSDate.date - @start_time) > 300
NSLog "MemoryTamer is using #{format_bytes(MemInfo.getMTMemory, true)}; restarting"
NSApp.relaunchAfterDelay(1)
end
cfm = get_free_mem
@statusItem.setTitle(Persist.store.show_mem? ? format_bytes(cfm.to_weak).to_weak : '') if Persist.store.update_while? || !@freeing
diff = (NSDate.date - @last_free)
Expand Down
9 changes: 9 additions & 0 deletions appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<link>https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version 0.9.6</title>
<sparkle:releaseNotesLink>
http://releases.io/henderea/MemoryTamer/0.9.6?heading=true
</sparkle:releaseNotesLink>
<pubDate>Tue, 12 Aug 2014 16:30:00 -0400</pubDate>
<enclosure url="http://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.6.zip" sparkle:version="0.9.6" length="4421237" type="application/octet-stream" />
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
</item>
<item>
<title>Version 0.9.5</title>
<sparkle:releaseNotesLink>
Expand Down
1 change: 1 addition & 0 deletions vendor/mem_info/mem_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
+ (int) getPagesInactive;
+ (int) getMemoryPressure;
+ (int) getTotalMemory;
+ (long long) getMTMemory;
@end
13 changes: 13 additions & 0 deletions vendor/mem_info/mem_info.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ + (int) getMemoryPressure {
+ (int) getTotalMemory {
return read_sysctl_int("hw.memsize");
}

+ (long long) getMTMemory {
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
if( kerr == KERN_SUCCESS ) {
//NSLog(@"rs: %lld ; vs: %lld", (long long)info.resident_size, (long long)info.virtual_size);
return info.resident_size;
} else {
NSLog(@"Error with task_info()");
return -1;
}
}
@end

0 comments on commit 8f266b1

Please sign in to comment.