Thread: Memory leaks. [DSPK] [PI]

Results 1 to 3 of 3
  1. #1 Memory leaks. [DSPK] [PI] 
    Banned
    Join Date
    Oct 2011
    Posts
    861
    Thanks given
    371
    Thanks received
    214
    Rep Power
    0
    First off either get somebody to help you with this.. or if you know how to fix a compiling error this should help.

    *Note I do not know if this has been released but I'm showing my own methods that friends and I have found. please do not flame hate or rant on this thread.

    NOTE TO MODERATORS:
    Please do not ban me as I am not taking credit that isn't mine.

    also:
    this is not spoonfed.

    int[]:
    Alright first off go to:
    [SPOIL]SOURCE.NAME.HERE\src\server\model\minigames[/SPOIL]
    and delete the world map folder.
    Now you will have some compiling errors. also remove from your compiler's .bat code. (edit it and this should be at the end of the compiler)
    [SPOIL]src\server\model\minigames\worldmap\*.java[/SPOIL]
    Assuming you don't use worldmap.
    But a huge majority of int memleaks are found here.

    Char[]:
    IMO this is the hardest one to get rid of.
    If you use DSPKs such as InsidiaX, CammyPvP, or HyBrId PvP
    remove unused minigames
    [Only registered and activated users can see links. ]
    also in config.java
    change
    [SPOIL]public static final int SAVE_TIMER[/SPOIL]
    to something like
    [SPOIL]public static final int SAVE_TIMER = 60/SPOIL]
    or higher. I found the save cycle really was not too helpful for the stability.(that is if it does it too quickly.)
    [SPOIL]public static final int TIMEOUT = 20;
    public static final int CYCLE_TIME = 600;
    public static final int BUFFER_SIZE = 10000;
    public static final int MAX_PROCESS_PACKETS = 20/SPOIL]
    This is the most stable for me. Depends on your vps (still in config)
    note:
    I removed player owned shops,
    it dropped 6 million bytes for char[] on insidiax.
    Spoiler for Misc.java:
    package server.util;

    import java.text.NumberFormat;

    public class Misc {

    public static String formatPlayerName(String str) {
    str = ucFirst(str);
    str.replace("_", " ");
    return str;
    }

    public static int getCurrentHP(int i, int i1, int i2) {
    double x = (double)i / (double)i1;
    return (int)Math.round(x*i2);
    }

    public static String longToPlayerName(long l) {
    int i = 0;
    char ac[] = new char[12];
    while(l != 0L) {
    long l1 = l;
    l /= 37L;
    ac[11 - i++] = playerNameXlateTable[(int)(l1 - l * 37L)];
    }
    return new String(ac, 12 - i, i);
    }

    public static String basicEncrypt(String s) {
    String toReturn = "";
    for (int j = 0; j < s.length(); j++) {
    toReturn += (int)s.charAt(j);
    }
    //System.out.println("Encrypt: " + toReturn);
    return toReturn;
    }

    public static String longToPlayerName2(long l) {
    int i = 0;
    char ac[] = new char[99];
    while(l != 0L) {
    long l1 = l;
    l /= 37L;
    ac[11 - i++] = playerNameXlateTable[(int)(l1 - l * 37L)];
    }
    return new String(ac, 12 - i, i);
    }

    public static final char playerNameXlateTable[] = {
    '_', 'a', 'b', 'c',
    'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
    'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
    '3', '4', '5', '6', '7', '8', '9'
    };

    public static String longToString(long l) {
    int i = 0;
    char ac[] = new char[12];
    while (l != 0L) {
    long l1 = l;
    l /= 37L;
    ac[11 - i++] = playerNameXlateTable[(int) (l1 - l * 37L)];
    }
    return new String(ac, 12 - i, i);
    }

    public static String format(int num) {
    return NumberFormat.getInstance().format(num);
    }

    public static String ucFirst(String str) {
    str = str.toLowerCase();
    if(str.length() > 1) {
    str = str.substring(0,1).toUpperCase() + str.substring(1);
    } else {
    return str.toUpperCase();
    }
    return str;
    }

    public static void print_debug(String str)
    {
    System.out.print(str);
    }
    public static void println_debug(String str)
    {
    System.out.println(str);
    }
    public static void print(String str)
    {
    System.out.print(str);
    }
    public static void println(String str)
    {
    System.out.println(str);
    }

    public static String Hex(byte data[])
    {
    return Hex(data, 0, data.length);
    }
    public static String Hex(byte data[], int offset, int len)
    {
    String temp = "";
    for(int cntr = 0; cntr < len; cntr++) {
    int num = data[offset+cntr] & 0xFF;
    String myStr;
    if(num < 16) myStr = "0";
    else myStr = "";
    temp += myStr + Integer.toHexString(num) + " ";
    }
    return temp.toUpperCase().trim();
    }

    public static int hexToInt(byte data[], int offset, int len)
    {
    int temp = 0;
    int i = 1000;
    for(int cntr = 0; cntr < len; cntr++) {
    int num = (data[offset+cntr] & 0xFF) * i;
    temp += (int)num;
    if (i > 1)
    i=i/1000;
    }
    return temp;
    }

    public static int random2(int range) {
    return (int)((java.lang.Math.random() * range) + 1);
    }

    public static int random(int range) {
    return (int)(java.lang.Math.random() * (range+1));
    }

    public static long playerNameToInt64(String s)
    {
    long l = 0L;
    for(int i = 0; i < s.length() && i < 12; i++) {
    char c = s.charAt(i);
    l *= 37L;
    if(c >= 'A' && c <= 'Z') l += (1 + c) - 65;
    else if(c >= 'a' && c <= 'z') l += (1 + c) - 97;
    else if(c >= '0' && c <= '9') l += (27 + c) - 48;
    }
    while(l % 37L == 0L && l != 0L) l /= 37L;
    return l;
    }


    private static char decodeBuf[] = new char[4096];
    public static String textUnpack(byte packedData[], int size)
    {
    int idx = 0, highNibble = -1;
    for(int i = 0; i < size*2; i++) {
    int val = packedData[i/2] >> (4-4*(i%2)) & 0xf;
    if(highNibble == -1) {
    if(val < 13) decodeBuf[idx++] = xlateTable[val];
    else highNibble = val;
    }
    else {
    decodeBuf[idx++] = xlateTable[((highNibble<<4) + val) - 195];
    highNibble = -1;
    }
    }


    return new String(decodeBuf, 0, idx);
    }

    public static String optimizeText(String text)
    {
    char buf[] = text.toCharArray();
    boolean endMarker = true;
    for(int i = 0; i < buf.length; i++) {
    char c = buf[i];
    if(endMarker && c >= 'a' && c <= 'z') {
    buf[i] -= 0x20;
    endMarker = false;
    }
    if(c == '.' || c == '!' || c == '?') endMarker = true;
    }
    return new String(buf, 0, buf.length);
    }

    public static void textPack(byte packedData[], java.lang.String text)
    {
    if(text.length() > 80) text = text.substring(0, 80);
    text = text.toLowerCase();

    int carryOverNibble = -1;
    int ofs = 0;
    for(int idx = 0; idx < text.length(); idx++) {
    char c = text.charAt(idx);
    int tableIdx = 0;
    for(int i = 0; i < xlateTable.length; i++) {
    if(c == xlateTable[i]) {
    tableIdx = i;
    break;
    }
    }
    if(tableIdx > 12) tableIdx += 195;
    if(carryOverNibble == -1) {
    if(tableIdx < 13) carryOverNibble = tableIdx;
    else packedData[ofs++] = (byte)(tableIdx);
    }
    else if(tableIdx < 13) {
    packedData[ofs++] = (byte)((carryOverNibble << 4) + tableIdx);
    carryOverNibble = -1;
    }
    else {
    packedData[ofs++] = (byte)((carryOverNibble << 4) + (tableIdx >> 4));
    carryOverNibble = tableIdx & 0xf;
    }
    }

    if(carryOverNibble != -1) packedData[ofs++] = (byte)(carryOverNibble << 4);
    }

    public static char xlateTable[] = {
    ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r',
    'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p',
    'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2',
    '3', '4', '5', '6', '7', '8', '9', ' ', '!', '?',
    '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\',
    '\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[',
    ']'
    };




    public static int direction(int srcX, int srcY, int destX, int destY)
    {
    int dx=destX-srcX, dy=destY-srcY;

    if(dx < 0) {
    if(dy < 0) {
    if(dx < dy) return 11;
    else if(dx > dy) return 9;
    else return 10;
    }
    else if(dy > 0) {
    if(-dx < dy) return 15;
    else if(-dx > dy) return 13;
    else return 14;
    }
    else {
    return 12;
    }
    }
    else if(dx > 0) {
    if(dy < 0) {
    if(dx < -dy) return 7;
    else if(dx > -dy) return 5;
    else return 6;
    }
    else if(dy > 0) {
    if(dx < dy) return 1;
    else if(dx > dy) return 3;
    else return 2;
    }
    else {
    return 4;
    }
    }
    else {
    if(dy < 0) {
    return 8;
    }
    else if(dy > 0) {
    return 0;
    }
    else {
    return -1;
    }
    }
    }

    public static byte directionDeltaX[] = new byte[]{ 0, 1, 1, 1, 0,-1,-1,-1 };
    public static byte directionDeltaY[] = new byte[]{ 1, 1, 0,-1,-1,-1, 0, 1 };


    public static byte xlateDirectionToClient[] = new byte[]{ 1, 2, 4, 7, 6, 5, 3, 0 };
    }

    I did not code this misc but it is better than the one most DSPK's have. I take no credit for it.

    Byte[]:
    [Only registered and activated users can see links. ]
    I've not messed around with it but this is my only advice I can give to you.

    General info:
    Try to remove any unneeded methods from your server, this will help quite a bit.
    I don't care if you know everything I have done here is wrong. All this worked for me so don't flame.
    There are lots of tuts out there that are hard to find, but good luck with your server's guys and have fun.
     

  2. #2  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    You do not have any idea what you are doing, do you? Could you explain each change, why each of these things was "leaking memory" in some detail? This is the informative section after all.
     

  3. #3  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Moved to Rs2 general + closed. Doesn't belong in Informative Threads, none of this info is valid, but I can't delete it without warning so that's why I've moved it.
    [Only registered and activated users can see links. ]
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. What causes the DSPK memory leaks?
    By CTucker in forum Help
    Replies: 2
    Last Post: 03-19-2011, 05:51 AM
  2. $20 Paypal - All DSPK Memory leaks
    By MerzA in forum Requests
    Replies: 8
    Last Post: 03-17-2011, 02:38 PM
  3. DSPK memory leaks
    By luke 2k9 in forum Requests
    Replies: 0
    Last Post: 03-14-2011, 12:00 AM
  4. Fixing DSPK memory leaks,
    By Anc13nts in forum Help
    Replies: 1
    Last Post: 03-01-2011, 11:06 AM
  5. Memory leaks DSPK
    By Shaqattack118. in forum Help
    Replies: 2
    Last Post: 02-17-2011, 10:57 PM
Tags for this Thread

View Tag Cloud

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