Take the 2-minute tour ×

i have this code vistaPrincipal.h

#import <UIKit/UIKit.h>

@interface vistaPrincipal : UIViewController

@property (retain, nonatomic) 
IBOutlet UIButton *botonHeros;

- (IBAction)botonHeros:(id)sender;



#import "vistaStrength.h"
#import "vistaPrincipal.h"

- (void)viewDidLoad


     [super viewDidLoad];


- (void)viewDidUnload

    [self setBotonHeros:nil];

    [super viewDidUnload];


- (IBAction)botonHeros:(id)sender {

    vistaStrength *vistaStr =[[vistaStrength alloc] initWithNibName:@"vistaStrength" bundle:nil];

    [self presentModalViewController:vistaStr animated:YES];

    [vistaStr release];



#import <UIKit/UIKit.h>

@interface vistaStrength : UIViewController

@property (retain, nonatomic) IBOutlet UIScrollView *scrollStrength;

@property (retain, nonatomic) IBOutlet UIButton *logoStrength;

@property (retain, nonatomic) IBOutlet UIButton *logoAgility;

@property (retain, nonatomic) IBOutlet UIButton *logoIntelligence;

- (IBAction)botonRegresar:(id)sender;


#import "vistaStrength.h"
#import "vistaPrincipal.h"

- (void)viewDidLoad{

    [super viewDidLoad];

    [scrollStrength setScrollEnabled:YES];
    [scrollStrength setContentSize:CGSizeMake(320,600)];


- (void)viewDidUnload{
    [self setScrollStrength:nil];
    [self setLogoStrength:nil];
    [self setLogoAgility:nil];
    [self setLogoInteligence:nil];

    [super viewDidUnload];


- (void)dealloc{
    [scrollStrength release];
    [logoStrength release];
    [logoAgility release];
    [logoInteligence release];

    [super dealloc];


- (IBAction)botonRegresar:(id)sender{

    vistaPrincipal *primeraVista =[[vistaPrincipal alloc] initWithNibName:@"vistaPrincipal" bundle:nil];

    [self presentModalViewController:primeraVista animated:YES];

    [primeraVista release];

in the transition of these views I'm losing memory What I can do?

share|improve this question
are vistaPrincipal and vistaStrength responsible citizens? –  Daniel A. White Oct 18 '11 at 20:13
Can you post the entire classes? Looks like your leak is in what has been allocated within them. –  Wolfert Oct 18 '11 at 20:15
BTW: Class names should begin with capital letters. It'll make your code a lot easier to read. –  bbum Oct 18 '11 at 20:17
Yeah, two questions. First of all - are both of these views taking care of their own deallocations correctly. And second, what do you mean by losing lots of memory? How are you quantifying this? In object creation? Are you seeing leaks? –  Simon Oct 18 '11 at 20:19

1 Answer 1

up vote 0 down vote accepted

Looks like you're not going back to vista principal, but allocating a fresh new intance of it? So the first instance of vistaPrincipal is still there, and rather than dismissing vistaStrentgh, you create a new instance on top of that. You now have 2 vistaprincipal in memory. If you go to vista strentgh again, you'll have 2 of each, then 3 - it'll gros infinitely.

In vista principal, rather than create a new vista principal, try calling [self.parentViewController dismissModalViewController]. If running on ios 5, make that [self.presentingViewController dismissModalViewController].

share|improve this answer

Your Answer


