English 中文(简体)
ICT 代表及母物体的设计记忆管理
原标题:iOS Design Pattern memory management with delegate and parent object

Im struggling to solve in a very clean way a problematic involving memory overload (management). Im having a serie of view that include other views, in my project I have a situation like this:

MainView

|_PageView

页: 1

远为好,容易做面包。 由于某些原因,习俗委员会中有一名代表(protocol),因此我们在第1页的“周期”中设立了国家习俗委员会,将代表列为第2页意见中的自称(PageVew 延伸了习俗ButtonDelegate),并释放了他们喜欢的县。

{
CustomButton *customButton_ = [[CustomButton alloc] initWithFrame:CGRectMake(100.0,50+(i*55.0),200.0);
customButton.delegate = self;
[self addSubView:customButton_];
[customButton_ release];
}

迄今为止,情况再次良好。 Button将是报章,p.View获得礼宾方法,做一些成文和oil。 一个问题是,在某一时刻,主文必须删除第1页的意见,因此,在我称之为一种方法中,

[pageView_ removeFromSuperview];
[pageView release], pageView_ = nil;

pageView_ = [PageView alloc] initWithFrame.....];

and I recreate the object with other data to display. I noticed that PageView never gets release and removed from the memory because its retainCount is exactly how many CustomButton I created inside PageView and assign the delegate to self plus one of course. My question is, what is the cleanest way to remove safely all the objects and be able to remove PageView too, free the memory (because Im loading a quite large amount of data to display in it) ?

Right now i m doing:

Create in PageView a NSMutableArray, that I CustomButton the objects in it, and before to remove PageView, I cycle it and set the delegate = nil and then release each object, after I release the NSMutableArray (called "holder").

但问题是,如果我想要与其他议定书一道增加更多的不同类型的物体,从而增加这一阵列,则可能导致其他保留物体的问题。

我在什么地方缺乏教义、知识,因此我需要研究更多(我可以说的)或我需要与另一个裁军厅接触?

感谢您的gu,我超负荷处理该问题,我的大脑被困在一条近距离的道路上。

最佳回答

代表<代码>retain property of CustomButton。 代表应为<条码>签字财产,而不是<条码>retain或<条码>。 见here

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签