我有一个 5 标签标签栏 Controller iPad 应用程序。
其中一个选项卡 (EKG) 导致内存问题。我运行了 Instruments,我能看到的是 malloc 分配不断增加,大约 12 分钟后,我所有的 View Controller 首先获得 didReceiveMemoryWarning 级别 1,然后是级别 2,然后 SigAbort 0 终止。
该应用程序的设计工作方式是,当 EKG 选项卡处于事件状态时,每 200 毫秒触发一次 setNeedsDisplay,以便在屏幕上绘制(绘制)EKG 样本。当我让应用程序正常运行时,它会在大约 12 分钟后终止。
但是,如果我保留 setNeedsDisplay 并注释掉 drawRect 中的代码,它将运行
永远。我不知道我的“drawRect”中有任何内存分配,但有人在做这些 mallocs 下面是我的 drawRect 代码:
- (void) drawRect : (CGRect) rect
{
int i, ii, x = 0, xx, y;
fEcgDraw = YES;
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextSetLineWidth (context, 1);
HH = 376;
if (fEcgErase == YES)
{
CGContextSetStrokeColorWithColor (context,
[UIColor blackColor].CGColor);
/*==============================================================================*/
/* Erase the last screen. */
/*==============================================================================*/
for (i = 0; i < 120; i++)
{
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGS[x]));
CGContextAddLineToPoint (context, ECGX[(x + 1)],
(HH - ECGS[((x + 1) % 119)]));
x++;
} // end - for (i = 0; i < 120; i++)
CGContextStrokePath (context);
fEcgErase = NO;
} // end - if (fEcgErase == YES)
else if (fECGLOOP)
{
xx = 1;
x = 0;
y = YY;
ii = 0;
for (i =
{
// if (xx == 1)
{
/*==============================================================================*/
/* First erase the prior ECG A/D plot value. */
/*==============================================================================*/
CGContextSetStrokeColorWithColor (context,
[UIColor blackColor].CGColor);
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGS[x]));
CGContextAddLineToPoint (context,
ECGX[(x + 1)],
(HH - ECGS[((x + 1))]));
CGContextStrokePath (context);
/*==============================================================================*/
/* Now plot the next ECG A/D plot value. */
/*==============================================================================*/
CGContextSetStrokeColorWithColor (context,
[UIColor whiteColor].CGColor);
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGY[y]));
CGContextAddLineToPoint (context,
ECGX[(x + 1)],
(HH - ECGY[((y + 1) % 119)]));
CGContextStrokePath (context);
ECGS[x] = ECGY[y];
x++;
y = ((y + 1) % 119);
} // end - if (xx == 1)
} // end - for (i = 0; i < 120; i++)
y = ((y + count1) % 119);
YY = y;
count1 = 0;
} // end - if (fEcgErase == YES)
fEcgDraw = NO;
} // end - 'drawRect'
/*===============================END OF FUNCTION================================*/
最佳答案
通过在每个“CGContextStrokePath”之前添加“CGContextClosePath”解决了问题,应用程序现在将永远运行而没有任何“didReceiveMemoryWarning”。
-吉尔·古德里奇
关于ios - iPad 上的 drawRect 导致内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7216165/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
这里有一个很好的答案解释了如何在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分配一个对象并返回该对象。这就是程序