【问题标题】:I'm new to Volley Networking library and facing this problem java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again我是 Volley Networking 库的新手,遇到这个问题 java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
【发布时间】:2018-10-08 07:41:15
【问题描述】:
  class RequestQueueClass constructor(context: Context) {
    companion object {
        @Volatile
        private var INSTANCE: RequestQueueClass? = null

        fun getInstance(context: Context) =
                INSTANCE ?: synchronized(this) {
                    INSTANCE ?: RequestQueueClass(context)
                }
    }

    val requestQueue: RequestQueue by lazy {
        // applicationContext is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        Volley.newRequestQueue(context.applicationContext)

    }

    fun <T> addToRequestQueue(req: Request<T>) {

        requestQueue.add(req)


    }
}

我正在声明一个单例 volley 请求处理程序类并在任何地方访问它,但问题是如何在惰性内部调用后使请求为空?

【问题讨论】:

    标签: kotlin android-volley


    【解决方案1】:

    我意识到我对这个问题有点晚了,但这是我的 2 美分:

    我看到您实际上并没有初始化您的 INSTANCE 对象,因此每次访问 getInstance 方法时,您都在使用应用程序上下文创建一个新队列,这就是为什么您可能会因为初始化请求队列而出现内存不足错误大量的内存

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-25
      • 1970-01-01
      • 2022-07-16
      • 1970-01-01
      相关资源
      最近更新 更多