Fixed a memory leak in Flow Cover.

Meh. This one was a nasty little bug. And now its fixed.

The problem is that in FlowCoverView, the dealloc routine was resetting the EAGLContext object early. This caused the rest of the dealloc call to fail, which then resulted in the overall view to fail to be released.

The fix is to rewrite the dealloc routine for FlowCoverView. Around line 230, replace the old -dealloc routine with:

- (void)dealloc 
{
    [EAGLContext setCurrentContext:context];

    [self destroyFrameBuffer];
    [cache release];

    [EAGLContext setCurrentContext:nil];
    
    [context release];
    context = nil;
    [super dealloc];
}

The first call to EAGLContext setCurrentContext makes sure the context is current, so all operations done on the various texture maps and OpenGL objects are done in the right context. Then everything is released–and at the end, the EAGLContext is then released, and so is the view.

I’ve also uploaded a new version of FlowCover which puts the FlowCover view on a second view; press the “test” button to have it pop up.

A new version of the code has been uploaded here. Download and incorporate into your code as you will.

Oh, and I also modified the code license; essentially you do not have to include mention of me in the binary redistribution; just the source code.

12 thoughts on “Fixed a memory leak in Flow Cover.

  1. Hi,

    The images are used here. But can i use UIView object for this animation? Currently i have changed the UIView into Image but am seeing only blank screen.

    Looking forward your reply.
    Thanks in advance.

    Like

  2. Hi,
    the present coverflow desisgn of yours is horizontal scrolling.I want to do vertical scrolling.So how to achive this using your existing code.Plz let me know how to do this.

    Like

  3. Hi,

    great project. Many thanks.

    I’m building a project now and will definitely credit you.

    One thing I’d love to add would be the ability to delete a tile (prettily!).

    I also needed to add a couple of methods to purge the images for a tile or all tiles (sometimes my images change with the same coverView).

    I added these to FlowCoverView

    -(void)purgeCache
    {
    for (int i = 0; i < [self numTiles]; i++) {
    NSNumber *num = [NSNumber numberWithInt:i];
    [cache removeObjectForKey:num];
    }
    }

    -(void)purgeTile:(NSInteger)tileIndex
    {
    NSNumber *num = [NSNumber numberWithInt:tileIndex];
    [cache removeObjectForKey:num];
    }

    and this to the cache:

    -(void)removeObjectForKey:(id)key
    {
    NSLog(@"removing data with key %@",key);

    // Update the age of the inserted object and delete the oldest if needed
    NSUInteger index = [fAge indexOfObject:key];

    if (index != NSNotFound) {
    [fAge removeObjectAtIndex:index];
    }

    [fDictionary removeObjectForKey:key];
    }

    Like

  4. It’s really nice, but I found some problem using it on real device.
    After some present/dismiss modal view controller with the FlowCover I get an error in createBuffer method of FlowCoverView class.
    This is the row that give me the problem 🙂

    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id)self.layer];

    I know that it happens after some try with an application that use a lot of memory, but i don’t know how to figure out.many thx.

    Have a nice weekend! 🙂

    Like

  5. its very wonderful,i need some help from your side.
    i tried to develop vertical coverflow scrolling with your code snippet.But i can’t change TEXTURESIZE(current 256) size.how can we change TEXTURESIZE size to 460 instead of 256.and also i need to develop scroll circular.

    please help me……

    Like

  6. Excellent project. I need to make one small mod, and it is giving me fits. I simply want to change the tile size to 180×100. I tried splitting TEXTURESIZE into COVERHEIGHT and COVERWIDTH, and replaced all of the hard coded 256, to no avail. If it has to be a power of two, 128×128 would be OK too. Can you point me in the right direction?

    Thanks!

    Like

  7. Pingback: The Easy Way to CoverFlow | yuezo.com

  8. I came across a crash when I flick through the images in the FlowCoverView and immediately hit the done button.

    Looks like the done action causes the FlowCoverViewController to be released, which causes the FlowCoverView’s delegate to zombie out.

    If the FlowCoverView’s touchesEnded is in progress during this time, it leads to a crasher.

    There may be a better way to fix this, but here’s what I attempted that seemed to have solved this problem:

    In the FlowCoverViewController’s dealloc method, I tried to access the FlowCoverView to set it’s delegate to nil:

    -(void)dealloc
    {
    NSArray *viewsArray = [self.view subviews];
    for (UIView*v in viewsArray)
    {
    if ([v isKindOfClass:[FlowCoverView class]])
    {
    FlowCoverView *fcv = (FlowCoverView*)v;
    fcv.delegate = nil;
    }
    }
    }

    Please let me know if anyone else noticed it or has a better solution.

    Thanks,
    Mansi

    Like

  9. Here’s how the dealloc looks like with the rest of the code block:
    -(void)dealloc
    {
    NSArray *viewsArray = [self.view subviews];
    for (UIView*v in viewsArray)
    {
    if ([v isKindOfClass:[FlowCoverView class]])
    {
    FlowCoverView *fcv = (FlowCoverView*)v;
    fcv.delegate = nil;
    }
    }
    [super dealloc];
    }

    just to avoid confusion 🙂

    Like

  10. Hi,

    Question:

    How do I load the TestFC.xib WITHOUT going to the first viewcontroller?

    I just want to view the Flow Cover view rightaway without clicking the button first.

    Please help..

    Thanks

    Like

  11. Hi,
    How to change UIImage in
    Delegate :

    - (void)flowCover:(FlowCoverView *)view didSelect:(int)image

    Like in iPhone music , touch to flip animation and describe feature in UIView like.
    Thanks .

    Like

Leave a reply to Krishnendra Cancel reply