×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Wink OutOfMemory Exception????????

    hi,
    i am doing project on image process. i am getting OutOfMemory Exception.
    i reduced size of image from 84*106 to 40*60 and further down.
    but it don't work. i have to process only 10 images.
    please tell me solution how can i solve it?

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: OutOfMemory Exception????????

    on which device is this ?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: OutOfMemory Exception????????

    first it occurs on emulator and then on n73

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: OutOfMemory Exception????????

    If it's happening on the emulator, then you need to trace the exception, and find out where it is being thrown.

  5. #5
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: OutOfMemory Exception????????

    mention the size of images and the procedure to initialize them. Post ur code here.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: OutOfMemory Exception????????

    thanks....
    image size is 84*106 and m using JAMA package for calculating
    matrix operation

    The line which are written in bold may cause problem
    as i removed them its working properly....



    /**
    * image size 84*106
    */
    public class Spl123 {

    double[][] eigenFace(double[][] face_v){ //face_v is [10][84*106]

    int length = 84*106;
    int nrfaces = 10;
    int i, j, col,rows, pix, image;
    double temp = 0.0;
    //double[][] faces = new double[nrfaces][length];
    double[] avgF = new double[length];

    /*
    Compute average face of all of the faces.
    */
    for ( pix = 0; pix < length; pix++) {
    temp = 0;
    for ( image = 0; image < nrfaces; image++) {
    temp += face_v[image][pix];
    }
    avgF[pix] = temp / nrfaces;
    }
    /*
    Compute difference.
    */
    for ( pix = 0; pix < length; pix++){
    for ( image = 0; image < nrfaces; image++) {
    face_v[image][pix] = face_v[image][pix] - avgF[pix];
    }
    }
    //System.arraycopy(face_v,0,faces,0,face_v.length);
    Sample faceM = new Sample(face_v, nrfaces,length);
    Sample faceM_transpose = faceM.transpose();
    Sample covarM = faceM.times(faceM_transpose);

    int a = covarM.getRowDimension();
    int b = covarM.getColumnDimension();
    // double[][] v = covarM.getArray();

    System.out.println(a);
    System.out.println(b);
    // System.out.println(avgF[1]);
    System.out.println(nrfaces);
    /*
    for(i = 0;i<a;i++)
    {
    for(j=0;j < b ; j++)
    {
    System.out.println(v[i][j]);
    }
    }
    /*
    Compute eigenvalues and eigenvector.
    */
    EigenvalueDecomposition E = covarM.eig();

    double[] eigValue = diag(E.getD().getArray());
    double[][] eigVector = E.getV().getArray();
    /*
    * We only need the largest associated values of the eigenvalues.
    * Thus we sort them (and keep an index of them)
    */
    int[] index = new int[nrfaces];
    double[][] tempVector = new double[nrfaces][nrfaces]; /* Temporary new eigVector */

    for ( i = 0; i <nrfaces; i++) /* Enumerate all the entries */
    index[i] = i;
    doubleQuickSort(eigValue, index,0,nrfaces-1);

    // Put the index in inverse
    int[] tempV = new int[nrfaces];
    for ( j = 0; j < nrfaces; j++)
    tempV[nrfaces-1-j] = index[j];

    index = tempV;

    /*
    * Put the sorted eigenvalues in the appropiate columns.
    */
    for ( col = nrfaces-1; col >= 0; col --) {
    for ( rows = 0; rows < nrfaces; rows++ ){
    tempVector[rows][col] = eigVector[rows][index[col]];
    }
    }
    eigVector = tempVector;
    eigValue = null;
    tempVector = null;
    Sample eigVectorM = new Sample(eigVector, nrfaces,nrfaces);
    eigVector = eigVectorM.times(faceM).getArray();


    /* Normalize our eigen vector matrix. */

    for ( image = 0; image < nrfaces; image++) {
    temp = max(eigVector[image]); // Our max
    for ( pix = 0; pix < eigVector[0].length; pix++)
    // Normalize
    eigVector[image][pix] = Math.abs( eigVector[image][pix] / temp);
    }


    return eigVector;
    }
    //*******************************************************
    public void fisherFace(double[][] face_f) //face_v is [10][84*106]

    {
    int length = 84*106;
    int nrfaces = 10;
    int nusr = 5;
    int i, j,k, m, pix, image,tp;
    double temp = 0.0;
    double[][] tmp = face_f;
    double[][] meanUser = new double[2][84*106];
    double[][] row1= new double[10][length];
    double[] avgTot = new double[length];
    double[][] row = new double[2][length];

    /*
    Compute average face of all of the faces.
    */
    for ( pix = 0; pix < length; pix++) {
    temp = 0;
    for ( image = 0; image < nrfaces; image++) {
    temp += tmp[image][pix];
    }
    avgTot[pix] = temp / nrfaces;
    }
    /*
    Compute difference.
    */
    for ( pix = 0; pix < length; pix++){
    for ( image = 0; image < nrfaces; image++) {
    tmp[image][pix] = tmp[image][pix] - avgTot[pix];
    }
    }

    /*
    * Calculate mean of one user
    */
    //m=0;
    for(k=0;k<2;k++)
    {
    if(k==0)
    {
    image= j =0;
    tp = nusr;
    }else
    {
    image = j = k*nusr;
    tp = image + nusr;
    }
    for ( pix = 0; pix < length; pix++) {
    temp = 0;
    for (image = j; image < tp; image++) {
    temp += face_f[image][pix];
    }
    meanUser[k][pix] = temp / nusr;
    }
    }
    /*Calculate diff bet one user and avg */
    for(k=0;k<2;k++)
    {
    for ( pix = 0; pix < length; pix++){
    row[k][pix] = meanUser[k][pix] - avgTot[pix];
    }
    }
    Sample faceM = new Sample(row);
    Sample faceM_transpose = faceM.transpose();
    double[][] Sb = (faceM_transpose.times(faceM)).getArray();
    Sample Sbb = new Sample(Sb);

    //Sb = Sbb.times(faceM).getArray();

    /*
    * Calculate (each of user image) - (avg of that user)
    */
    m=0;
    for(k=0;k<2;k++)
    {
    for(i=0;i<5;i++,m++)
    {
    for ( pix = 0; pix < length; pix++)
    {
    row1[m][pix] = face_f[m][pix] - meanUser[k][pix];
    }
    }
    }

    faceM = new Sample(row1);
    faceM_transpose = faceM.transpose();
    // Sample Sw = faceM.times(faceM_transpose);

    double[][] Sw = (faceM_transpose.times(faceM)).getArray();
    Sample Sww = new Sample(Sw);
    //Sw = Sww.times(faceM).getArray();
    /*
    * Calculation of face space
    */
    meanUser = null;
    row = row1 = null;
    avgTot = null;
    // length = nusr = null;

    tmp = eigenFace(face_f);

    Sbb = new Sample(Sb);
    Sample tr = new Sample(tmp);
    Sample tr1 = tr.times(Sbb);
    tr = tr.transpose();
    Sbb = tr1.times(tr);

    Sww = new Sample(Sw);
    tr = new Sample(tmp);
    tr1 = tr.times(Sww);
    tr = tr.transpose();
    Sww = tr1.times(tr);

    }

    //*****************************************************************
    static double max(double[] a) {
    double b = a[0];
    for (int i = 0; i < a.length; i++)
    if (a[i] > b) b = a[i];

    return b;
    }

    static double[] diag(double[][] m) {

    double[] d = new double[m.length];
    for (int i = 0; i< m.length; i++)
    d[i] = m[i][i];
    return d;
    }
    /**
    * Quick sort on a vector with an index.
    *
    * @param a the array of numbers. This will be modified and sorted
    * ascendingly (smalles to highest)
    * @param index the index of the numbers as related to original
    * location.
    * @param lo the index where to start from. Usually 0.
    * @param hi the index where to stop. Usually a.length()
    */
    static void doubleQuickSort(double a[], int index[], int lo0, int hi0) {
    int lo = lo0;
    int hi = hi0;
    double mid;

    if ( hi0 > lo0) {

    /* Arbitrarily establishing partition element as the midpoint of
    * the array.
    */
    mid = a[ ( lo0 + hi0 ) / 2 ];
    // loop through the array until indices cross
    while( lo <= hi ) {

    while( ( lo < hi0 ) && ( a[lo] < mid )) {
    ++lo;
    }


    while( ( hi > lo0 ) && ( a[hi] > mid )) {
    --hi;
    }

    // if the indexes have not crossed, swap
    if( lo <= hi ) {
    swap(a, index, lo, hi);
    ++lo;
    --hi;
    }
    }

    if( lo0 < hi ) {
    doubleQuickSort( a, index, lo0, hi );
    }

    if( lo < hi0 ) {
    doubleQuickSort( a, index,lo, hi0 );
    }
    }
    }
    static private void swap(double a[], int[] index, int i, int j) {
    double T;
    T = a[i];
    a[i] = a[j];
    a[j] = T;
    // Index
    index[i] = i;
    index[j] = j;
    }


    }
    Last edited by akshaychaudhari; 2009-04-08 at 19:15.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    37

    Re: OutOfMemory Exception????????

    Assign null value to the objects and arrays which are not required this may help you KEEP TRYING

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: OutOfMemory Exception????????

    i tried it
    its not working properly
    Last edited by akshaychaudhari; 2009-04-08 at 18:40.

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: OutOfMemory Exception????????

    That code looked expensive!

    Remember that an array of doubles is eight bytes per element. So, (84 * 106 * 10) doubles at eight bytes each, comes to around 800k.

    I recommend you consider a less memory-intensive algorithm.

  10. #10
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: OutOfMemory Exception????????

    thanks for replying....
    i reduced size to 40*60 and no of images from 5 to 3 still it shows error

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: OutOfMemory Exception????????

    I suggest you use the memory analyser in the Wireless Toolkit. Then you will see where the memory is being used.

    The problem is simply that you are using too much memory.

  12. #12
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: OutOfMemory Exception????????

    Hi,
    You must check this with the memory monitor...as grahm suggest...
    And after a while you keep on calling Garbage collector from the memory monitor...and you will come to know that exactly how much is the memory required...watch the graph carefully,
    check the object by clicking the objects Tab..
    Also make sure that you are not creating any arrays,images,or so in in a loop...A deep code review is recommended..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. s60 3rd ed emulator crash
    By Kimau in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2008-06-18, 22:12
  2. outOfMemory exception on device with 2mb memory
    By gx in forum Mobile Java General
    Replies: 6
    Last Post: 2007-05-24, 10:33
  3. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  4. how to avoid OutofMemory Exception
    By lakshmanraob in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-10-28, 14:53
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •