Deleting a object

Everytime when i try to use CC_SAFE_DELETE, or delete method in a object. The program crashes.
The main idea of the game is, objects enter into the scene and when they out, i need to delete them. Or when player dies, i need to delete them too. Calling the destructors, i have the same issue.

Can you post an example of what you are doing? Construction, Destruction, etc.

This is the creation code of object:

Aviao * Aviao::Criar(HelloWorld * game,Point posicao,Point pombopos,Point (*caminho)(float t,Point avip,Point pombp)){
    	Aviao * aviao = new Aviao(game,posicao,pombopos,caminho);
    	if(aviao){
    		aviao->iniciar();
    		aviao->autorelease();
    		return aviao;
    	}
    	CC_SAFE_DELETE(aviao);
    	return NULL;
    }

that is the code of removing objects:

for(i;i<5;i++){
		Aviao *avi;
		avi =(Aviao *) avioes->getObjectAtIndex(i);

			avioes->removeObjectAtIndex(i);
			avi->setVisible(false);
			avi->setPosition(0,0);
			avi->retain();
		CC_SAFE_DELETE(avi);
			
		}

and then , the program crashes.
Note: I am storing objects into an array.
Note2:These objects inherit the classes and box2d ccsprite.

I cant pinpoint what, but something looks weird about the inside of the for loop. Let me mock up a similar example.

as far as i know, CC_SAFE_DELEATE will check if the pointer is NULL and delete it otherwise. When you remove your object from the array its reference count will be zero and the object will be destroyed. But the pointer still has a valid address (is not NULL). So CC_SAFE_DELETE will try to delete it again and crash your program.
When you create an object using a create method and add to a node or a CCArray its reference count will be automatically handled for you, so no need to call delete yourself.