几天以来,我遇到了一些非常奇怪的内存问题。
问题是,有时应用程序会卡住并开始快速增加内存使用量,直到崩溃。当内存增加时,应用程序完全卡住。
经过一些调试后,我确定是这段代码导致了错误:
angular.module('app.shared').factory('PushNotificationService', PushNotificationService);
PushNotificationService.$inject = [
'$q',
'MessagingService'
];
function PushNotificationService($q, MessagingService) {
var me = this;
initialize();
return {
getStartupMessage: getStartupMessage,
fetchToken: fetchToken
};
/**
* Constructor
* @return {[type]} [description]
*/
function initialize() {
me.pusher = null;
me.deviceToken = null;
me.startupMessage = null;
}
/**
* Fetches the push token through device interface
*
* @return {$q} Promises
*/
function fetchToken() {
if (me.pusher != null) {
return $q(function(resolve, reject) {
console.log('PushService.fetchToken(): Got pusher', me.pusher);
// when pusher was already initialized, we do not need to fetch it again
console.log('PushService.fetchToken(): Token was already retrieved', me.deviceToken);
resolve(me.deviceToken);
});
}
console.log('PushService.fetchToken(): Needs to fetch token bc not retrieved yet');
return $q(function(resolve, reject) {
document.addEventListener('deviceready', function() {
console.log('PushService.fetchToken(): Device is ready', typeof resolve, typeof reject);
resolve(true);
}, false);
}).then(function() {
console.log('PushService.fetchToken(): No pusher retrieved yet, do it now');
return __initialize();
}).then(function(push) {
console.log('PushService.fetchToken(): Got pusher and start attaching events to it', push);
return $q(function(resolve, reject) {
push.on('error', function(error) {
console.log('PushNotificationService.fetchToken(): Error while retrieving token', error.message, error);
reject(error);
});
push.on('registration', function(data) {
console.log('PushNotificationService.fetchToken(): Successfully retrieved token', data);
me.deviceToken = data.registrationId;
resolve(data.registrationId);
});
console.log('PushNotificationService.fetchToken(): Eventhandlers of pusher', push._handlers);
});
});
}
/**
* Initializes the push notifications and tries to fetch the Push token
* @return {Cordova.Pusher} [description]
*/
function __initialize() {
me.pusher = PushNotification.init({
android: {
senderID: "288503736094"
},
ios: {
alert: true,
badge: true,
sound: true,
clearBadge: true
},
windows: {}
});
me.pusher.on('notification', __incomingNotification);
return me.pusher;
}
// additional code which is not relevant here...
// .....
// .....
}
它只发生在 iOS 上并且完全随机,无法在崩溃中找到系统。
调试日志如下所示:
PushService.fetchToken(): Needs to fetch token bc not retrieved yet
PushService.fetchToken(): Device is ready function function
PushService.fetchToken(): No pusher retrieved yet, do it now
PushService.fetchToken(): Got pusher and start attaching events to it {"_handlers":{"registration":[],"notification":[null],"error":[]},"options":{"android":{"senderID":"288503736094"},"ios":{"alert":true,"badge":true,"sound":true,"clearBadge":true},"windows":{}}}
PushNotificationService.fetchToken(): Eventhandlers of pusher {"registration":[null],"notification":[null],"error":[null]}
最佳答案
这是 cordova-ios 中的一个问题,导致随机位置发生大量内存泄漏。
升级到最新版本修复了它!
关于ios - 初始化推送通知时 ionic 的奇怪内存泄漏导致卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35841820/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
在我的gem中,我需要yaml并且在我的本地计算机上运行良好。但是在将我的gem推送到rubygems.org之后,当我尝试使用我的gem时,我收到一条错误消息=>"uninitializedconstantPsych::Syck(NameError)"谁能帮我解决这个问题?附言RubyVersion=>ruby1.9.2,GemVersion=>1.6.2,Bundlerversion=>1.0.15 最佳答案 经过几个小时的研究,我发现=>“YAML使用未维护的Syck库,而Psych使用现代的LibYAML”因此,为了解决
我在Rails工作并有以下类(class):classPlayer当我运行时bundleexecrailsconsole然后尝试:a=Player.new("me",5.0,"UCLA")我回来了:=>#我不知道为什么Player对象不会在这里初始化。关于可能导致此问题的操作/解释的任何建议?谢谢,马里奥格 最佳答案 havenoideawhythePlayerobjectwouldn'tbeinitializedhere它没有初始化很简单,因为你还没有初始化它!您已经覆盖了ActiveRecord::Base初始化方法,但您没有调
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
ruby如何管理内存。例如:如果我们在执行过程中采用C程序,则以下是内存模型。类似于这个ruby如何处理内存。C:__________________|||stack|||------------------||||------------------|||||Heap|||||__________________|||data|__________________|text|__________________Ruby:? 最佳答案 Ruby中没有“内存”这样的东西。Class#allocate分配一个对象并返回该对象。这就是程序
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我正在写一篇关于在Ruby中几乎一切都是对象的博客文章,我试图通过以下示例来展示这一点:classCoolBeansattr_accessor:beansdefinitialize@bean=[]enddefcount_beans@beans.countendend所以从类中我们可以看出它有4个方法(当然,除非我错了):它可以在创建新实例时初始化一个默认的空bean数组它可以计算它有多少个bean它可以读取它有多少个bean(通过attr_accessor)它可以向空数组写入(或添加)更多bean(也通过attr_accessor)但是,当我询问类本身它有哪些实例方法时,我没有看到默认