English 中文(简体)
记忆泄露:自食谱。
原标题:Memory leak: self.tableView.backgroundView

请允许我向我提出一些建议,说明我为什么会把记忆泄露到这个线上:

“enterography

最佳回答

如果你看从建设和分析中发出的警告,你就会注意到,警告实际上适用于你的法典第38条,而不是显示信息的第39条。

第38条,请<代码>alloc,即,请将记忆分配给

Every alloc, new, copy, and retain requires a matching release or autorelease. So, the compiler is warning you that you have called alloc but haven t called a corresponding release anywhere.

您可在第38行文中添加<代码>autorelease:

self.tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Back_01.jpg"]] autorelease];

如果您不想使用<代码>autorelease。 那么,你就可以利用这样的东西:

UImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Back_01.jpg"]];
self.tableView.backgroundView = bgImage;
[bgImage release];

唯一真正的区别是,在汽车库排水时,<代码>autorelease等到跑道结束时,而电话release则有可能很快释放记忆。

问题回答

The UIImageView on line 38 is leaking. You should add autorelease, like so:

self.tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Back_01.jpg"]] autorelease];




相关问题
Weak event handler model for use with lambdas

OK, so this is more of an answer than a question, but after asking this question, and pulling together the various bits from Dustin Campbell, Egor, and also one last tip from the IObservable/Rx/...

JavaScript memory problem with canvas

I m using getImageData/putImageData on a HTML5 canvas to be able to manipulate a picture. My problem is that the browser never seems to free any memory. Not until I close the tab (tested in Chrome and ...

Memory leak for CComBSTR

I have read that the following code causes memory leak. But did not understand why. CComBSTR str; pFoo->get_Bar(&str); pFoo->get_Baf(&str); How does it cause a leak when we are not ...

Hunting memory leaks

I m finding leaked heap blocks by using the following command in WinDbg !heap –l With each leaked heap block I get, I m running to following to get the stack trace. !heap -p -a leakedheapblock The ...

NSScanner memory leak

I m at my first experiences with iPhone development. I wrote some basic code to test the NSScanner class, and now I was looking into the Leaks tool. It seems that this code is leaking, when in the ...

Do Small Memory Leaks Matter Anymore?

With RAM typically in the Gigabytes on all PC s now, should I be spending time hunting down all the small (non-growing) memory leaks that may be in my program? I m talking about those holes that may ...

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

热门标签