Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-02-2009, 11:54 AM   #2 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,563
Default

addSubview also increased the retain count of the subview. Until you remove the subviews from m_contentView OR m_contentView is destroyed, the subviews will not be released by the superview.

I would also move your [m_bkg[i] release] up futher in the code, closer to where you init the imageviews; then you don't have to release them later, just get them removed from the superview or release the superview.

This is how you can add the subviews and release them right away:

Code:
	for (int i=0;i<NB_BKG;i++)
	{
		m_bkg[i]=[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 320.0)];
		[m_contentView addSubview:m_bkg[i]];
		[m_bkg[i] release];
		[m_bkg[i] setImage:[TestViewCtrlAppDelegate thumbnailImage:[NSString stringWithFormat:@"test%02d",i]]];

	}

In fact, I'm not sure you need the m_bkg array at all, if its only purpose was to release the imageviews. Maybe it has another purpose?
__________________
smasher is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,064
Threads: 38,852
Posts: 170,454
Top Poster: smasher (2,563)
Welcome to our newest member, HenLeop934
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.