release an array of uimageviews

Discussion in 'iOS Programming' started by juanchofern, Jan 30, 2012.

  1. juanchofern, Jan 30, 2012
    Last edited by a moderator: Jan 30, 2012

    juanchofern macrumors newbie

    Joined:
    Jan 30, 2012
    #1
    Hello i have an array of uiimage views in a function.

    But the problem is when i call the function is sometimes i would like
    to change the images, so how could i do it and releasing the memory
    to avoid memory leaks.

    FicherosBolasGrises is a NSMutable array of strings where i save the names
    Of the images files.

    In another function if i need it i change the images in FicheroBolasGrises,
    The problem is when i call the function to assign the images to the array
    of image views i have memory leaks because i have not releases before, how i could release the array of image views to avoid memory leaks?
    Any help?

    Thanks a lot

    this is my function
    Code:
    fullarray
    {
    imageBolaGris = [ImageCache loadImage:[ficherosBolasGrises objectAtIndex:i]];	
    
    tBolasGrises[i] = [[UIImageView alloc] initWithImage:imageBolaGris];
    }
    
    Thanks a lot for your help
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Loop over the array releasing every object.
     
  3. juanchofern, Jan 30, 2012
    Last edited by a moderator: Jan 30, 2012

    juanchofern thread starter macrumors newbie

    Joined:
    Jan 30, 2012
    #3
    Hello, that i tried this way, inside the loop, but it doesn´t work.

    Could you help me? Thanks a lot.

    Code:
    [tBolasGrandes [i] release];
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4


    You need to consider what you are asking. If a user reported a problem with your app as "it doesn't work" would you consider that a good bug report or less than helpful and want to smack them round the head? To be clear:

    What did you expect to happen? Explain in detail. What actually happened and how did this differ from what you expected. Again explain in detail. What have you done to debug the problem (note if the answer is nothing you will get no help): explain each step you have taken to debug the problem, the results you got and what that tells you.

    Are there error messages? If so what are they.

    Basically: learn to provide the detail required to assist or expect to get little back.
     
  5. juanchofern, Jan 30, 2012
    Last edited by a moderator: Jan 30, 2012

    juanchofern thread starter macrumors newbie

    Joined:
    Jan 30, 2012
    #5


    Do you know how can i release the array of uimageviews when i want
    to change the images?

    The array is Style Old C.

    Code:
    UIImageView tBolasGrandes[5];

    this is my code

    Code:
    for (int i =0; i<5;i++)
                    {
    imageBolaGrande = [ImageCache loadImage:[ficherosBolasGrandes objectAtIndex:i]];
    
    tBolasGrandes[i] = [[UIImageView alloc] initWithImage:imageBolaGrande];
                    }
    so in another function i would like to change ficherosbolasGrandes to assign
    new images.

    ficherosBolasGrandes is a NSMutableArray. This is not a problem, i can
    release ficherosBolasGrandes and add new images.

    Then after i would like to release tBolasGrandes to avoid memory leaks and assign the new images from ficherosBolasGrandes.

    Could you help me please?

    Thanks a lot, and regards.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    You have not answered any of the questions I asked. You said you had tried. Where is this code? What did not work? How did you try and debug it?

    If you expect someone else to write your code for you then I think you will be out of luck.
     

Share This Page