   CudaSafeCall( cudaMalloc((void**)&dev_postings, sizeof(PostingTfIdf) * terms) );
   CudaSafeCall( cudaMemcpy(dev_postings, postings, sizeof(PostingTfIdf) * terms, cudaMemcpyHostToDevice) );
 
+  // these variables saves all pointers in postings
+  // needed to deallocate postings from gpu memory
+  dev_postings_docIds_pointers = (int **) malloc(sizeof(int *) * terms);
+  dev_postings_weights_pointers = (float **) malloc(sizeof(float *) * terms);
+
   int i;
   int *dev_docIds;
   float *dev_weights;

int blocks; // blocks number depend on nomber of docs in collection

// global variables that are allocated in device
// during index allocating in gpu
// and used during evaluation
PostingTfIdf *dev_postings;
float *dev_docsNorm;
int terms;
int docs;


  if (!terms && !docs) return;

  // free docs norm
  printf("Cuda: Deallocating old docs norm from memory\n");
  cudaFree(dev_docsNorm);

  // free postings
  printf("Cuda: Deallocating old postings from memory\n");
  int i; for(i=0; i<terms; i++){
    cudaFree(dev_postings_weights_pointers[i]);
    cudaFree(dev_postings_docIds_pointers[i]);
  }
  cudaFree(dev_postings);
  free(dev_postings_weights_pointers);
  free(dev_postings_docIds_pointers);
}
