删除对象时内存不释放 - 在正确的ARC释放方式上不清楚(Memory not releasing when removing object - unclear on proper way to release in ARC)
Xcode 5,iOS7
我有一个应用程序在循环中创建UILabels,并在数组中引用它们。 在反复调用'创建'方法后,我注意到我的内存使用量增加了。 我想清除数组和相关的UILabel对象来释放内存,因为它看起来不会出现在我当前的代码中。 相反,每次通过我的循环时,我都可以看到我的记忆体使用量在增加,而且从未减少 我目前正在使用Storyboard和ARC。
我如何正确地释放UILabels,因为看起来ARC没有为我做这件事?
@implementation myViewController CGPoint tmpPoint; NSMutableArray *allDots; /// more code here // // This method is called repeatedly from another loop -(void)createLabels{ //remove any previous labels //I'm pretty sure this is not actually clearing the UILabels but rather the pointer to the labels? for(short i=0; i<10; i++){ UILabel *junkDot=[allDots objectAtIndex:i]; junkDot=nil; } // Either of these statements should clear the references/pointers // [allDots removeAllObjects]; allDots=[[NSMutableArray alloc] init]; //create a new group of labels for(short i=0; i<10; i++){ // code to generate Point values [self makeLabel:tmpPoint]; } } -(UILabel*)makeLabel:(CGPoint)thePoint{ CGRect xFrame=CGRectMake(thePoint.x, thePoint.y, 40, 20); UILabel *tmpLabel=[[UILabel alloc] initWithFrame:xFrame]; [self.view addSubview:tmpLabel]; [allDots addObject:tmpLabel]; return tmpLabel; }
Xcode 5, iOS7
I have an app that creates UILabels in a loop, referencing them in an array. After repeatedly calling the 'creation' method I'm noticing that my memory usage increases. I'd like to clear the array and the related UILabel objects to free the memory, as it appears it not happening with my current code. Instead, each time through my loops I can see my memory usage increasing and never decreasing. I am currently using Storyboards and ARC.
How can I properly release the UILabels since it seems ARC is not doing it for me?
@implementation myViewController CGPoint tmpPoint; NSMutableArray *allDots; /// more code here // // This method is called repeatedly from another loop -(void)createLabels{ //remove any previous labels //I'm pretty sure this is not actually clearing the UILabels but rather the pointer to the labels? for(short i=0; i<10; i++){ UILabel *junkDot=[allDots objectAtIndex:i]; junkDot=nil; } // Either of these statements should clear the references/pointers // [allDots removeAllObjects]; allDots=[[NSMutableArray alloc] init]; //create a new group of labels for(short i=0; i<10; i++){ // code to generate Point values [self makeLabel:tmpPoint]; } } -(UILabel*)makeLabel:(CGPoint)thePoint{ CGRect xFrame=CGRectMake(thePoint.x, thePoint.y, 40, 20); UILabel *tmpLabel=[[UILabel alloc] initWithFrame:xFrame]; [self.view addSubview:tmpLabel]; [allDots addObject:tmpLabel]; return tmpLabel; }
原文:https://stackoverflow.com/questions/24477167
相关问答
更多-
使用: $("#map_canvas").gmap({'zoom':7}) 当map已经被初始化并且不会返回一个jQuery对象时,可以使用option-method,所以它不可链接(将会解释你得到的错误)。 Use: $("#map_canvas").gmap({'zoom':7}) The option-method can be used when the map is already initialized and will not return a jQuery-object, so it's ...
-
创建一个像这样的URI: http://maps.google.com/?q=[lat],[long] 例如: http://maps.google.com/?q=-37.866963,144.980615 或者,如果您使用的是JavaScript API map.setCenter(new GLatLng(0,0)) 这和其他有用的信息来自这里: http://code.google.com/apis/maps/documentation/javascript/reference.html#Map th ...
-
使用marker.getPosition()您将获得具有latitude和longitude属性的LatLng对象。 所以,你可以这样做: Double latitude = marker.getPosition().latitude; Double longitude = marker.getPosition().longitude; 希望能帮助到你! With marker.getPosition() you get a LatLng object which has a latitude and l ...
-
我终于想通了。 我似乎遇到了关闭问题。 但是所有的答案/修复都显示了如何使用原生的javascript googl maps api来解决这个问题,这是一个非常冗长的解决方案/代码,而不是JQuery-ui-map api。 以下是我的最终代码: //Function Retuning the Info window click event function function makeInfoWindowEvent(address) { return function() { ...
-
选择器中没有空格。 lat=jQuery("input#lat").val(); long=jQuery("input#long").val(); ("input #something")表示它选择id为#something的所有输入的子#something 。 如果没有找到任何内容, .val()将返回undefined,map不起作用。 No spaces in selectors. lat=jQuery("input#lat").val(); long=jQuery("input#long").va ...
-
您不希望为显示事件创建单独的事件 - 使其成为创建(或移动)标记的代码的一部分,如下所示: function placeMarker(location) { if (marker == undefined){ marker = new google.maps.Marker({ position: location, map: map, animation: google.maps.Animation.DROP ...
-
好吧 - 这真的不太理想,但我发现另一个集群插件似乎工作正常: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/examples/simple_example.html 我不得不对我的代码做一些调整(因为你需要push标记push入一个数组,而不是正常添加它们 - 然后做一个衬里使它成为簇)。 基本上你只需要创建一个新数组: var markers = []; 然后将它们“推”到数组中: var ...
-
http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-basic-example.html $('#map_canvas').gmap().bind('init', function(ev, map) { $('#map_canvas').gmap('addMarker', {'position': '57.7973333,12.0502107', 'bounds': true}).click(function( ...
-
如何使用jquery-ui-map插件使用Google Maps Stylers?(How to use Google Maps Stylers with jquery-ui-map plugin?)[2022-12-07]
有很多地方可以把它放在例如地图的实例化中: 现在: $('#map_canvas').gmap() //...more code 然后: $('#map_canvas').gmap({styles:[{stylers:[{lightness:7},{saturation:-100}]}]}) //...more code gmap-constructor接受google.maps.Map.setOptions()接受的所有选项。 其中一个选项是“style”,它应该是一个带有google.maps. ... -
您需要将标记的“边界”选项更改为false。 $('#map_canvas').gmap('addMarker', {'position': clientPosition, 'bounds': false}); 如果将属性边界设置为true,则地图将自动计算视口和缩放,覆盖构造函数中的任何缩放集Blockquote 这是一个更多信息的链接 you need to change the 'bounds' option of the marker to false. $('#map_canvas').gmap( ...